Thanks Chouser for the clear explanation. When I stepped away from the screen and took some time to actually think, I came to a basic conclusion that you so well described; having that Clojure code is executed at a different time to the actual code that is targeted on the javascript vm.
I am currently looking to utilize the `require-macros` for implement a validation component in a web based system. The macro(s) could expand into valid ClojureScript code, for `validation logic`, that is accessible by both the Clojure code (the back-end) and the ClojureScript code (the front-end). -Alen On Aug 8, 8:37 pm, Chouser <chou...@gmail.com> wrote: > On Mon, Aug 8, 2011 at 12:59 PM, Alen Ribic <alen.ri...@gmail.com> wrote: > > It seems that the only way to reference Clojure code [1] from the > > ClojureScript namespace is via the ns require-macros keyword. > > Is this correct and if so, why the reference to macros only and not to > > general functions too. (I'm sure there is a good reason if it is the > > case; I'm hoping to get a better understanding). > > Clojure is not available to the JavaScript runtime that is actually > executing the ClojureScript. It is often easy to port some Clojure > code to ClojureScript but of course in that case it's actually > ClojureScript code with is easy enough to :require in your > ClojureScript code. > > :require-macros is different because macros are only used at *compile* > time. So you can :require-macros to pull in a Clojure namespace, and > those Clojure macros can use any Clojure functions they want to, but > that all happens while the ClojureScript is being compiled. The > macros must produce valid ClojureScript code so that it can be > compiled to JavaScript, at which point it has lost all access to > Clojure and must make do with ClojureScript and JavaScript functions. > > --Chouser -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en