1

when I read SICP Section 2.2.2, we declare a sequence as

(define x (cons (list 1 2) (list 3 4)))

Then, when press x from my own DrRacket IDE and also the textbook, the result expression for this evaluation is printed as

((1 2) 3 4)

I mean, this expression seems a little bit weird to me, since (list 1 2) and (list 3 4) are equivalent semantically, so I guess the expression for such a data structure might be something like

((1 2) (3 4))

Anyone please point out why the upper result is correct? Also suppose we have such a expression, is there just one solution to recover a tree data structure by iterpreting such a expression?

Mark Dong
  • 59
  • 2
  • 8
  • Sequences are produced by the use of the function `list`. the function `cons`, on the other hand, produces pairs. Try `(cons 1 (list 3 4))`, `(cons (list 1 2) (list 3 4))`, `(list (list 1 2) (list 3 4))`. Another important point to notice is that in the Lisp language, containers can hold disparate data, i.e the entries are not necessarily the same semantically. – Will Ness Feb 17 '23 at 17:51
  • Also try `'(1 . 3)`, `'(1 . (2 . 3))`, `'(1 . (2 3))`, `'(1 . ())`. These are the printed representations of Lisp data constructions where every `.` corresponds to a call to `cons`. – Will Ness Feb 17 '23 at 17:55
  • and, of course, try `'((1 2) . (3 4))`. – Will Ness Mar 15 '23 at 08:05

0 Answers0