(eq? 1 (car '(1 2 3))) returns #f

Apr 27, 2010 at 3:27 PM

In the REPL:

> (car '(1 2 3))
1

> (eq? 1 (car '(1 2 3)))
#f

I'm new to Scheme, so I don't know if I'm doing something wrong, but that should return #t, shouldn't it?

Cheers,
Mark 

Coordinator
Apr 27, 2010 at 4:00 PM

 

Hi Mark

eq? is like a pointer comparison, it could or could not return #t for that.

For numbers, you should use another predicate, eg, = or fx=?. This will test if the values are equal.

Regards

leppie

May 25, 2010 at 11:22 AM

Hi Leppie,

Sorry, thank you for the reply. I've been working through the Little Schemer, which it seems may be slightly out of date.

Any sign of RTW? :)

Cheers,
Mark