0

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

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

2 Answers2

1

'((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 ().

Renzo
  • 26,848
  • 5
  • 49
  • 61
1

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 '().

Martin Půda
  • 7,353
  • 2
  • 6
  • 13
  • Thank you actually I didn't want to create a list with '() and '(a b c d) I just wanted to understand the outcome but it's still useful thanks again ! – mario kebab Feb 15 '23 at 07:56
  • 1
    @mariokebab The point is that to answer the question "What is this list's `cdr`?", you can alternatively ask "How could I build this list with `cons`?". Whatever the second argument to `cons` was, that's what the `cdr` is. – amalloy Feb 15 '23 at 08:01