Subject: gensym vs make-symbol [was: Re: newbie: please don't smash my case ]
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 2000/07/09
Newsgroups: comp.lang.lisp
Message-ID: <8k8t64$374i0$1@fido.engr.sgi.com>
Erik Naggum  <erik@naggum.net> wrote:
+---------------
| * Rainer Joswig
| | Unless you create non-interned symbols. ;-)
| 
|   So complete the list of functions by adding make-symbol.  Furrfu.
+---------------

Now that you bring it up, here's a (style?) question I've been wanting
to ask (still being somewhat only a casual user of CL):

Other than reducing possible confusion while debugging with "macroexpand",
is there any real reason to prefer (gensym "foo") over (make-symbol "foo")
when defining macros that need non-capturing local variables? Both produce
fresh uninterned symbols which can't conflict with (capture) any other symbol.
So in what circumstances is one preferred over the other, or vice-versa?


-Rob

p.s. I think I know why one doesn't use literal uninterned symbols for
such things, e.g.:

	(defmacro foo (arg1 arg2 &body body)
	  (let ((tmp '#:tmp))			; BUG!
	    ...stuff that uses ,tmp ...))

You only get *one* uninterned symbol when the macro is defined, which
gets used for all possible instances of the macro. So if you had nested
occurrences, in the expansion an inner occurrence of #:tmp could shadow
an outer one. But that can't happen with:

	(defmacro foo (arg1 arg2 &body body)
	  (let ((tmp (make-symbol "tmp")))
	    ...stuff that uses ,tmp ...))

because "make-symbol" gets called for each occurrence.

-----
Rob Warnock, 41L-955		rpw3@sgi.com
Applied Networking		http://reality.sgi.com/rpw3/
Silicon Graphics, Inc.		Phone: 650-933-1673
1600 Amphitheatre Pkwy.		PP-ASEL-IA
Mountain View, CA  94043