Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

To be clear, that ` character is called "syntax-quote" (in Clojure; "quasi-quote" elsewhere) and it's the "templating" part. It's both possible and common to use macros without syntax-quote and vice versa.

In fact, common practice in Clojure is to define a your macros in terms of a backing function:

    (defn foo-fn [body]
      (fancy stuff here that probably uses syntax-quote somewhere))

    (defmacro foo [& body]
      (foo-fn body))
Clojure's style of macro system is known as a "procedural" macro system because the macros can be any arbitrary procedures which returns code as data. There are other types of macro systems, like Scheme's syntax-rules, which are more directly embrace the fact that most macros are tree rewrites.


Syntax-quote is a little bit different from quasiquote. Clojure's macros look a lot like Common Lisp's unhygienic macros, but Clojure's syntax-quote offers a sort of "hygiene by default" by forcing namespaces on variables and making it hard to introduce non-gensym symbols accidentally.





Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: