Re: which one of these with-gensym implementations is better?
- From: Alan Crowe <alan@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: 27 Dec 2006 22:20:54 +0000
"cmo" <amalawi@xxxxxxxxx> writes:
PCL:
(defmacro with-gensyms ((&rest names) &body body)
`(let ,(loop for n in names collect `(,n (gensym)))
,@body))
GLPS:
(defmacro with-gensyms (symbols body)
(sublis (mapcar #'(lambda (sym)
(cons sym (gensym (string sym)))) symbols)
body))
the only difference that I noticed was the fact that you need to use
comma before variables in PCL with-gens while you do not need to do
that in the other implementation.
any other differences, insights.
The second is horribly broken. It goes inside quoted data
and arguments to macros destroying the data. For example:
CL-USER> (macroexpand-1 '(with-gensyms (a b)
(let ((a '(somedata b c))
(b '(moredata c b a)))
(do stuff with a))))
(LET ((#:A1599 '(SOMEDATA #:B1600 C))
(#:B1600 '(MOREDATA C #:B1600 #:A1599)))
(DO STUFF WITH #:A1599))
Using backquote and comma seems unavoidable because you are
trying to get to this situation:
CL-USER> (macroexpand-1 '(with-gensyms (a b)
`(let ((,a '(somedata b c))
(,b '(moredata c b a)))
(do stuff with ,a))))
(LET ((A (GENSYM)) (B (GENSYM)))
`(LET ((,A '(SOMEDATA B C)) (,B '(MOREDATA C B A)))
(DO STUFF WITH ,A)))
T
CL-USER> (eval *)
(LET ((#:G1605 '(SOMEDATA B C)) (#:G1606 '(MOREDATA C B A)))
(DO STUFF WITH #:G1605))
Between macroexpansion time and run time some A's have been
replaced by gensyms, while other A's have been left, their
time is yet to come. CL needs the programmer to be explicit
about when things are done, whether at macroexpansion time
or at run time.
Alan Crowe
Edinburgh
Scotland
.
- References:
- Prev by Date: Checksum (noob)
- Next by Date: slime and clisp: any way to get stack trace info?
- Previous by thread: Re: which one of these with-gensym implementations is better?
- Next by thread: finding color support of emacs for editing lisp
- Index(es):