Why clojurescript macros can't be written in clojurescript?

假装没事ソ 提交于 2019-12-04 16:29:34

问题


While clojure and clojurescript features are basically the same (apart from obvious differences), macros are not. When I want a macro in clojurescript I have to write it in clojure and require it with require-macros. Is that a technical limitation of javascript or just a design decision? Why can't both be the same?


回答1:


From ClojureScript: Up and Running by Stuart Sierra and Luker VanderHart, page 69:

Macros are applied during the compilation process. They do not exist at runtime. Because the ClojureScript compiler is implemented in Clojure, ClojureScript macros must be written in Clojure, not ClojureScript. Fortunately, Clojure and ClojureScript are almost identical when it comes to manipulating data structures, so switching between the two languages is not difficult.

What that means is that macro code gets executed in Clojure world and not in the browser, so it must be written in plain Clojure.



来源:https://stackoverflow.com/questions/18381052/why-clojurescript-macros-cant-be-written-in-clojurescript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!