What is the result of this in scheme: (cdr '((a b c d)))

69 Views Asked by At

Isn't it supposed to be (a b c d) ??

When I try it on Racket it gives me () .

2

There are 2 best solutions below

0
Renzo On

'((a b c d)) is a list, containing only one element, that is the four-element list (a b c d). So if you get the car of it, you obtain as result (a b c d), while the cdr produces correctly the empty list ().

2
Martin Půda On

How would you create such a list using cons?

(cons (cons 'a (cons 'b (cons 'c (cons 'd '()))))
      '())

or

(cons '(a b c d) '())

cdr returns the second element of the given pair, so it returns '().