help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: comparing symbols coming from gensym?


From: Alan Mackenzie
Subject: Re: comparing symbols coming from gensym?
Date: Wed, 24 Aug 2005 08:24:52 +0000
User-agent: tin/1.4.5-20010409 ("One More Nightmare") (UNIX) (Linux/2.0.35 (i686))

Joe Corneli <jcorneli@math.utexas.edu> wrote on Tue, 23 Aug 2005 23:50:46
-0500:

> Why is it that

> (setq a (gensym)) ;=> G2007
> a                 ;=> G2007
> (equal a 'G2007)  ;=> nil

> while 

> (setq a 'foo)    ;=> foo
> a                ;=> foo
> (equal a 'foo)   ;=> t

> ?

This is because your gensymmed symbol, 'G2007, has only been
"half-created".  It hasn't been "interned" in the "obarray", the
structure which holds (almost) all symbols - that 'G2007 is a
free-floating symbol.

When you do (equal a 'G2007), this _creates_ a full-bloodied
industrial-strength NEW _interned_ symbol G2007, since there wasn't
already such a symbol in the obarray.  This is distinct from your
gensymmed one.

That is, in fact, the whole point of gensym - to create a symbol distinct
from any other symbol which ever has been or ever will be.  You asked for
it, you got it!  If you want to actually _use_ it, you'll need something
like (symbol-value a)

Look up `gensym' in the CL manual, and `intern' in the Elisp manual.

-- 
Alan Mackenzie (Munich, Germany)

Email: aacm@muuc.dee; to decode, wherever there is a repeated letter
(like "aa"), remove half of them (leaving, say, "a").


reply via email to

[Prev in Thread] Current Thread [Next in Thread]