Growing a DSL with Clojure by Ambrose Bonnaire-Sergeant.
From the post:
From seed to full bloom, Ambrose takes us through the steps to grow a domain-specific language in Clojure.
Lisps like Clojure are well suited to creating rich DSLs that integrate seamlessly into the language.
You may have heard Lisps boasting about code being data and data being code. In this article we will define a DSL that benefits handsomely from this fact.
We will see our DSL evolve from humble beginnings, using successively more of Clojure’s powerful and unique means of abstraction.
You know, the “…code being data and data being code” line reminds me of DATATAG in ISO 8879 (SGML).
I suspect this gets us keys being first class citizens but that will have to await another post.
DATATAG was a mess, but in Lisp it really is true that data is code and vice versa, which can indeed be exploited to easily build DSLs. It’s quite common to build Prolog implementations in Lisp, for example, and you can do that quite easily by using defmacro to translate to Lisp, which then gets compiled to machine code (if you use the right Lisp.)
Paul Graham’s On Lisp is an absoutely outstanding book that really goes into this in depth.
Comment by larsga@garshol.priv.no — July 21, 2011 @ 4:21 am
I checked the prices on Paul Graham’s On Lisp, ouch!
Have you looked at Clojure much? Wondering if it has the same range of capabilities? I am posting a note today on a Clojurescript, which targets JavaScript for deployment.
Thinking that could be useful for people writing web interfaces for TM applications.
Comment by Patrick Durusau — July 21, 2011 @ 6:08 am
Thanks to a poke from @ambroseb I quite easily found a pdf version of “On Lisp” at: http://www.paulgraham.com/onlisptext.html. Thanks!
Comment by Patrick Durusau — July 22, 2011 @ 10:25 am