The platform i’m working with is DrScheme.
I’ve seen that a pair (a b) [constructed by (cons a b)] is implemented within the language like a procedure that looks like this:
(define (cons a b)
(lambda(pick)
(cond ((= pick 1) a)
((= pick 2) b))))
and the selectors:
(define (car x) (x 1))
(define (cdr x) (x 2))
Then there are lists, constructed with expression like (cons a (cons b (cons c (cons ...)))).
Now, what i was trying to understand is this (typed on DrScheme’s prompt):
> (define l1 '(a b c))
> (define l2 (list 'a 'b 'c))
> l1
(a b c)
> l2
(a b c)
> (eq? l1 l2)
#f
Ok, l2 is just a list (that is, a procedure, ect…) like i’ve described abode, but… what is l1? A symbol? A sequence of character? And whatever it is, how is it implemented within the language?
Thanks!
l1is also just a list containing the same elements. Note that this also returns#f:While this returns
#t:The reason is that
eq?checks whetherl1andl2are references to the same object in memory, whileequal?checks whether they have the same contents.