On Sun, Sep 5, 2010 at 5:24 AM, Kazimir Majorinc kazimir@chem.pmf.hr wrote:
Imagine that someone invited you to write the presentation "Five best CL macros ... I seen" or "Five best CL macros ... I wrote." What would you chose and why?
This is one of my favorite example macros. Although in this simple form it's not something I use in real code, I do use a variation on this theme all the time. The best part about it is, there are few languages other than Lisp in which a tree walk can be so neatly encapsulated into an iteration primitive.
(defmacro do-leaves (var tree &body body) "Walks TREE, a list structure; for any descendant that is not a list, binds VAR to it and executes BODY." `(labels ((rec (,var) (when ,var (if (listp ,var) (progn (rec (car ,var)) (rec (cdr ,var))) (progn ,@body))))) (rec ,tree)))
-- Scott