Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why clojurescript macros can't be written in clojurescript?

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?

like image 644
islon Avatar asked Aug 22 '13 12:08

islon


1 Answers

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.

like image 184
Serabe Avatar answered Nov 09 '22 22:11

Serabe