Re: Nested &REST parameter vs. single named parameter
- From: dkixk@xxxxxxxxxxxxx (Damien Kick)
- Date: Fri, 18 Nov 2005 02:37:04 GMT
In article <m2zmo595xf.fsf@xxxxxxxxxxxxxxx>, Peter Seibel
<peter@xxxxxxxxxxxxxxx> wrote:
>
> FWIW, here's the version of WITH-GENSYMS from my macro-utilities library.
>
> (defmacro with-gensyms ((&rest names) &body body)
> `(let ,(loop for n in names collect `(,n (make-symbol ,(string n))))
> ,@body))
>
> I think I used a different version in my book because I didn't want to
> have to bother explaining the difference between MAKE-SYMBOL and
> GENSYM.
I had thought at some point that using make-symbol should be as good as
gensym but then I started to wonder about if one had nested
macroexpansions that used the same name. Each make-symbol would create a
unique uninterned symbol but with the same printed representation. This
might not be the most concise example:
Damien-Kicks-Computer:~/tmp dkick$ cat duff.lisp
(in-package #:pg-user)
(eval-when (:compile-toplevel :load-toplevel :execute)
(defmacro my-with-gensyms ((&rest names) &body forms)
`(let ,(loop for n in names
collect `(,n (gensym ,(concatenate 'string
(symbol-name n)
"/"))))
,@forms))
(defmacro duff (&body forms)
(my-with-gensyms (x y z)
`(let ((,x 13)
(,y 69)
(,z 71))
(progn
(list ,x ,y ,z)
(list ,@forms)))))
(defmacro fudd (&body forms)
(my-with-gensyms (x y z)
`(duff ',x ',y ',z ,@forms))))
(eval-when (:compile-toplevel :load-toplevel :execute)
(defmacro my-with-make-symbols ((&rest names) &body forms)
`(let ,(loop for n in names
collect `(,n (make-symbol ,(symbol-name n))))
,@forms))
(defmacro duff* (&body forms)
(my-with-make-symbols (x y z)
`(let ((,x 13)
(,y 69)
(,z 71))
(progn
(list ,x ,y ,z)
(list ,@forms)))))
(defmacro fudd* (&body forms)
(my-with-make-symbols (x y z)
`(duff* ',x ',y ',z ,@forms))))
Damien-Kicks-Computer:~/tmp dkick$
And then from the REPL
CL-USER> (in-package #:pg-user)
#<Package "PLAYGROUND-USER">
;;;; Compile file /Users/dkick/tmp/duff.lisp ...
PG-USER> (as pprint
(as macroexpand-1
'(duff 1 2 3)))
(LET ((#:X/118 13) (#:Y/119 69) (#:Z/120 71))
(PROGN (LIST #:X/118 #:Y/119 #:Z/120) (LIST 1 2 3)))
; No value
PG-USER> (as pprint
(as macroexpand-1
'(fudd 1 2 3)))
(DUFF '#:X/121 '#:Y/122 '#:Z/123 1 2 3)
; No value
PG-USER> (as pprint
(as macroexpand
'(fudd 1 2 3)))
(LET ((#:X/127 13) (#:Y/128 69) (#:Z/129 71))
(PROGN (LIST #:X/127 #:Y/128 #:Z/129)
(LIST '#:X/124 '#:Y/125 '#:Z/126 1 2 3)))
; No value
PG-USER> (as pprint
(as macroexpand-1
'(duff* 1 2 3)))
(LET ((#:X 13) (#:Y 69) (#:Z 71)) (PROGN (LIST #:X #:Y #:Z) (LIST 1 2 3)))
; No value
PG-USER> (as pprint
(as macroexpand-1
'(fudd* 1 2 3)))
(DUFF* '#:X '#:Y '#:Z 1 2 3)
; No value
PG-USER> (as pprint
(as macroexpand
'(fudd* 1 2 3)))
(LET ((#:X 13) (#:Y 69) (#:Z 71))
(PROGN (LIST #:X #:Y #:Z) (LIST '#:X '#:Y '#:Z 1 2 3)))
; No value
PG-USER>
Does anyone else see this as a problem with using make-symbol?
.
- References:
- Nested &REST parameter vs. single named parameter
- From: Michael J. Forster
- Re: Nested &REST parameter vs. single named parameter
- From: Peter Seibel
- Re: Nested &REST parameter vs. single named parameter
- From: Damien Kick
- Nested &REST parameter vs. single named parameter
- Prev by Date: Re: Norvig's use of APPPLY for MATRIX-TRANSPOSE puzzled me!
- Next by Date: Re: Norvig's use of APPPLY for MATRIX-TRANSPOSE puzzled me!
- Previous by thread: Re: Nested &REST parameter vs. single named parameter
- Next by thread: Re: Nested &REST parameter vs. single named parameter
- Index(es):