在 ClojureScript 中,有时不能总是将表单替换为其宏展开的表单。对于 defrecord 和其多参数版本的 defn 也是如此。
clj -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.11.60"}}}' -M -m cljs.main
ClojureScript 1.11.60
cljs.user=> (defrecord ARecord [a])
cljs.user/ARecord
cljs.user=> (macroexpand '(defrecord ARecord [a]))
(let* [] (do (defrecord* ...)))
cljs.user=> (let* [] (do (defrecord* ...)))
WARNING: Wrong number of args (4) passed to ARecord at line 1 <cljs repl>
WARNING: Wrong number of args (4) passed to ARecord at line 1 <cljs repl>
WARNING: Wrong number of args (4) passed to ARecord at line 1 <cljs repl>
WARNING: Wrong number of args (4) passed to ARecord at line 1 <cljs repl>
WARNING: Wrong number of args (4) passed to ARecord at line 1 <cljs repl>
WARNING: Wrong number of args (4) passed to cljs.user/ARecord at line 1 <cljs repl>
WARNING: Wrong number of args (4) passed to cljs.user/ARecord at line 1 <cljs repl>
在评估由此宏展开而产生的表单时也会发生相同的情况
(macroexpand '(defn foo ([a] (foo a 5)) ([a b] (+ a b))))