2024 Clojure 状态调查! 中分享你的想法。

欢迎!请访问关于页面了解该网站的一些基本信息。

0
 Juan Monetta's avatar ClojureScript
编辑于

在 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))))

登录注册以回答此问题。

...