Explanation of macros; Haskell macros

Peter Seibel peter at javamonkey.com
Thu Oct 30 12:09:04 EST 2003


Joachim Durchholz <joachim.durchholz at web.de> writes:

> Efficiency issues aside: how are macros more intuitive than quoting?

Because they let you write what you intuitively expect (assuming your
intuitions are tuned a particular way, I suppose). In Common Lisp,
WHEN is a macro that lets you write this:

  (when (> x y) (print x))

If you tried to write it as a function using quoting to prevent
evaluation you might try this:

  (when (> x y) '(print x))

which won't work in general because of the iniability for the code
inside WHEN to evaluate the data '(print x) in the lexical environment
where it appears.

Or you could do this:

  (when (> x y) #'(lambda () (print x)))

which could work but seems a bit convoluted (i.e. unintuitive)
compared to the macro version.

-Peter

-- 
Peter Seibel                                      peter at javamonkey.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp




More information about the Python-list mailing list