Joe Black
Joe Black

Reputation: 11

Comparing symbols in Lisp

Of course I am a novice but why doesn't this return T?

(eql (third '(0 1 'to 0 1)) 'to)
==> nil

But this does return the quoted 'to.

(third '(0 1 'to 0 1))
'TO

As you might guess, none of the compare forms work, eq, eql, equal, equalp.

Upvotes: 1

Views: 237

Answers (1)

Rainer Joswig
Rainer Joswig

Reputation: 139251

Because

'TO

is not EQL to

TO

The first is a list with two symbols as elements. It's actually (QUOTE TO).

The second is just a symbol.

? (EQL ''TO 'TO)
NIL

See:

? (equal (third '(0 1 'to 0 1)) ''TO)
T

You tried to quote a symbol in a literal list, which usually makes no sense, since literal lists are not evaluated inside.

Upvotes: 8

Related Questions