How can I return true for + and (first (rest '(1 + 2))) being equal?
(first (rest '(1 + 2))) is +
But (equal (first (rest '(1 + 2))) + ) returns NIL! I tried the other
equality operators but none seem to work...
thanks
In article <·····················@news.dbn.net>, "rio"
<······@hotmail.com> wrote:
> How can I return true for + and (first (rest '(1 + 2))) being equal?
>
> (first (rest '(1 + 2))) is +
That's right. But + is evaluated not necessarily (see below) +.
It is the value of the variable +,
which happens to be predefined in Common Lisp.
> But (equal (first (rest '(1 + 2))) + ) returns NIL! I tried the other
> equality operators but none seem to work...
You want: (equal (first (rest '(1 + 2))) '+)
Since otherwise + would be treated as a variable.
Using QUOTE (or short written as ' ) prevents
this.
If you want to compare symbols, EQ is sufficient.
(with-excursion
Depending on the history of evaluation
(equal (first (rest '(1 + 2))) + ) may be true:
? +
NIL
? (equal (first (rest '(1 + 2))) + )
T
Why that? See:
http://www.xanalys.com/software_tools/reference/HyperSpec/Body/var_plcm_plplcm_plplpl.html
)
--
Rainer Joswig, Hamburg, Germany
Email: ·············@corporate-world.lisp.de
Web: http://corporate-world.lisp.de/
From: Xenophon Fenderson the Carbon(d)ated
Subject: Re: testing for equality of + and (first (rest '(1 + 2)))
Date:
Message-ID: <w4ozokwk5kj.fsf@lovecraft.irtnog.org>
>>>>> "rio" == rio <······@hotmail.com> writes:
rio> But (equal (first (rest '(1 + 2))) + ) returns NIL! I tried
rio> the other equality operators but none seem to work...
You forgot to quote the last plus sign. Remember, if you don't quote
a symbol, Lisp will look up its binding. + is probably unbound (or
bound to NIL), and '+ and 'NIL (the symbols themselves) are, of
course, not equal.
(equal (first (rest '(1 + 2))) '+)
works in Corman Lisp (as well as EQ and EQL).
HTH,
#\X
--
UN-altered reproduction and DISSEMINATION of this IMPORTANT information is
ENCOURAGED
From: Barry Margolin
Subject: Re: testing for equality of + and (first (rest '(1 + 2)))
Date:
Message-ID: <_2Nz5.21$O96.904@burlma1-snr2>
In article <···············@lovecraft.irtnog.org>,
Xenophon Fenderson the Carbon(d)ated <········@irtnog.org> wrote:
>You forgot to quote the last plus sign. Remember, if you don't quote
>a symbol, Lisp will look up its binding. + is probably unbound (or
>bound to NIL), and '+ and 'NIL (the symbols themselves) are, of
>course, not equal.
Actually, + is usually bound to the previous expression you typed into the
top-level read-eval-print loop.
--
Barry Margolin, ······@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.