[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
- To: FREND at MIT-MC
- From: Alan Bawden <ALAN at MIT-MC>
- Date: Sun, 16 Dec 79 14:58:00 GMT
- Cc: BUG-LISP at MIT-MC
- Original-date: 16 December 1979 09:58-EST
Date: 16 DEC 1979 0800-EST
From: FREND at MIT-MC (M. Alexander Bloom)
Why does (equal x '||) give T when x has been assigned '|| by setq,
but give nil when x gets (seemingly) the same
value from readline?
I tested the result from (setq x (readline t)) and got ||
but this failed in the (equal x '||)
Is there a reason for the null string to have more than one internal
This is not a bug. First of all there is nothing magic about symbols
whose name is "". If you try
(setq a (readline))foo
the value of a will be a symbol named "foo". But you will find that
(equal '|foo| a) returns nil. This is because there is nothing in
lisp to prevent you from having two symbols with the same name.
Perhaps some further explanation is in order.
Symbols returned by READ are uniquized by registering them in a table
called the "obarray", this process is called "interning" and
gaurantees that READ will never return two different symbols with the
same name. Some other functions that handle symbols also intern them,
IMPLODE, for example, takes a list of characters (expressed as fixnums
or symbols) and returns you an interned symbol whose name is made up
of those characters. There is also a function INTERN which a takes a
symbol and returns you a symbol with the same name that is registered
on the obarray.
The function READLINE doesn't bother to return an interned symbol,
since when you call READLINE you are probably going to do string-like
operations on the result and so you don't care about whether you have
a unique copy of that symbol.
The function EQUAL compares symbols not by looking at their names, but
simply by looking to see if they are the SAME object (what the
function EQ does), this is done mostly for efficiency's sake and is a
small price to pay since it is usually what you want (so don't suggest
that we make THAT change). I suspect that what you want is the
function SAMEPNAMEP which takes two symbols and compares their names
to see if they are the same and returns T if they are. This is the
function to call if you are treating symbols as just plain strings.