[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Optimizing rebindings in macros
- To: info-macl@cambridge.apple.com
- Subject: Optimizing rebindings in macros
- From: Ranson <ranson@lannion.cnet.fr>
- Date: 11 Mar 91 14:10:00
- Cc: ranson@lannion.cnet.fr
- X400-received: by /PRMD=inria/ADMD=atlas/C=fr/; Relayed; 11 Mar 91 14:08:34+0100
- X400-received: by /PRMD=CNET/ADMD=ATLAS/C=FR/; Relayed; 11 Mar 91 14:10:00
As REM@SUWATSON.stanford.edu has mentionned to me, my idea (not rebinding
atomic arguments) does not work with more than one argument, because it may
change evaluation order. For instance:
(defmacro test(x y)
(let ((xx (gensym))(yy (gensym)))
`(let ((,xx ,x)(,yy ,y))
(list ,xx ,yy ,xx ,yy))))
(setq u 1)
(test u (setq u 2))
-> (1 2 1 2)
Now if I optimize the binding xx:
(defmacro opt-test(x y)
(if (consp x)
(let ((xx (gensym))(yy (gensym)))
`(let ((,xx ,x)(,yy ,y))
(list ,xx ,yy ,xx ,yy)))
(let ((yy (gensym)))
`(let ((,yy ,y))
(list ,x ,yy ,x ,yy)))))
(setq u 1)
(opt-test u (setq u 2))
-> (2 2 2 2)
This was my contribution to the illustration of the danger of macros :-)
Daniel Ranson.
ranson@lannion.cnet.fr