Re:On Lisp
by thurn on Sunday August 25, 2013 @11:00PM
(#6274929)
What percentage of the techniques in this book are also applicable to Clojure programming? I don't know a lot about how the two macro systems differ.
[ Parent
| on HN ]
On Lisp is great for learning about macros, and what is possible.
That being said, what is idiomatic in CL is not necessarily idiomatic clojure. For example, pg tends to like anaphoric macros, (http://en.wikipedia.org/wiki/Anaphoric_macro), while Clojure tends to eschew them.
Have a look at http://thinkrelevance.com/blog/tags/on-lisp to see Stuart Halloway going through On Lisp in Clojure.
A fair amount of the examples involve mutation; a practice that Clojure discourages. A lot of the macros are very instructive, however.
Indeed, On Lisp has an excellent discussion of
mutation and its use in programs written in a functional style. In discussing destructive functions, Graham describes the ways in which they can be used with reasonable safety - e.g. immediately mutating a list newly created by a mapping function.
The reasons one might do so in Clojure are likely to bear similarity to those provided by Graham - speed and memory - despite the vastly greater resources of today's computers versus those of 1991.
Very good point. Mutation is extremely useful when birthing a new data structure; this is a time when it's not yet visible to the rest of the system so the danger of sharing intermediate state does not occur. Clojure has a very elegant facility for dealing with this particular scenario:
A lot of it. Clojure has a Common Lisp like macro system. There are some slight changes where clojure tried to make things a little simple, and the syntax is a lot diffrent.
I think there are people on the internet who have implmented most of the example in clojure.