views:

291

answers:

5

Hey,

I'm reading "Programming Clojure" and I'm interested in a book that discusses how to create macros as extensive as possible.

Do you suggest a book for this?

Thanks.

+4  A: 

Although they're both aimed at Common Lisp, two great books for this are On Lisp by Paul Graham (full book available free online at his website) and Let Over Lambda by Doug Hoyte.

Of the two On Lisp is more accessible; even though Clojure macros are IIRC more similar to Scheme's hygienic macros, you'll still almost certainly learn something from it.

Derrick Turk
+8  A: 

The quintessential book on Lisp macros is probably Paul Graham's On Lisp. It used Common Lisp, though, but that doesn't matter too much if what you really want to look at it macros, although Clojure's are different on a number of levels. (Clojure being a Lisp-1, to begin with.)

Isaac Hodes
+1. In addition to "On Lisp", I would also recommend reading about Scheme's hygienic macros, Lisp-1 vs Lisp-2 and also dig Clojure mailing list posts on how it solves the hygiene problem in a smart way using namespace qualified symbols.
Ramakrishnan Muthukrishnan
A: 

It's not exactly a general-purpose macro-writing book, but AMOP demonstrates how to use macros as a 'view' layer for a library/framework.

(Hmm, I'm not doing a very good job describing this. AMOP is a book which kind of defies categorization!)

Ken
+1  A: 

The book "Practical Common Lisp" explains Lisp macros very clearly. Clojure's macros are similar enough to those of Common Lisp that pretty much all of what you'd learn would carry over. "Let Over Lambda", while a fun, interesting, and creative work, uses Lisp macros very differently from the way they're used by most serious, experienced, practical Lisp programmers. I don't recommend the use of "anamorphic" macros (that "know" about specific variable names).

Dan Weinreb
A: 

Michael Fogus' upcoming book The Joy of Clojure, available through Manning's Early Access Program, has a good chapter on macro's. It's an excellent book explaining the mindset behind functional programming, and not only how, but also why Clojure's features (including the newest 1.2 changes) are implemented the way they are.

The chapter on macro's explains the following use cases for macro's in Clojure, how they can be implemented, and how they are processed:

defining control structures
combining forms
changing forms
returning forms
control symbolic resolution time
manage resources

NielsK