Re:Why Lisp macros are cool, a Perl perspective (2005)
by gus_massa on Thursday December 04, 2014 @05:57AM
(#8698696)
Another place where macros in Lisp fail is that they may evaluate an expression twice. (Using the Scheme dialect, because I don't write good enough CL.)
This can be solved using a temporary variable as in the original article,
But it's easier because you don't have to declare the type of temp. Also Scheme has hygienic macros, so you don't need to use gensym to avoid the variable capture of temp.
[ Parent
| on HN ]
Re:Why Lisp macros are cool, a Perl perspective (2005)
by sjolsen on Thursday December 04, 2014 @11:28AM
(#8700020)
> Another place where macros in Lisp fail is that they may evaluate an expression twice
Strictly speaking, macros don't evaluate their expressions at all.
Square is a bad example, though. Macros are not for writing function-like expressions; they're for extending (or more generally transforming) the syntax of the language. Inline functions and compiler macros are more appropriate tools for things like square.
Re:Why Lisp macros are cool, a Perl perspective (2005)
by gus_massa on Thursday December 04, 2014 @11:41AM
(#8700095)
> Strictly speaking, macros don't evaluate their expressions at all.
OK, you are right.
A better example is a bad implementation of a short circuiting or:
(define-syntax-rule (bad-or x y)
(if x x y))
It can't be a function because sometimes you don't want to evaluate y, but in the resulting code x is sometimes executed twice.