XUtils

metaclj

staged compilation


Meta-Clojure

Overview

Meta-Clojure provides staged compilation for Clojure. It includes a form of syntax quoting that is aware of both local environments and special-forms. Among other things, this makes many macros easier to write. Perhaps more importantly, it simplifies control over when code gets evaluated or compiled.

Meta-Macros

The defmeta form is analogous to defmacro, but is expected to return Syntax objects (forms plus their environments) instead of plain forms.

(defmeta my-if [test then else]
  (syntax (if test then else)))

Note that you don’t need to unquote any of the parameters to if, since the syntax form is aware of the meta-macro’s environment.

Call-By-Name

Since it’s common for macros to have a body that always templates code with a syntax-quoter, the convenience macro defbn provides a way to create “call-by-name” macros:

(defbn my-if [test then else]
  (if test then else))

Both versions of my-if have correct “lazy” behavior: they will only evaluate one arm of the conditional.

References

  • [Multi-stage Programming][1]
  • [Terralang][2]
  • [MetaOCaml][3]
  • [EClj][4]
  • [Exotypes][5]

Articles

  • coming soon...