In SICP exercise 2.26 using DrScheme, why does cons return a list, instead of a pair of lists?
Posted
by limist
on Stack Overflow
See other posts from Stack Overflow
or by limist
Published on 2010-05-27T14:17:12Z
Indexed on
2010/05/27
14:21 UTC
Read the original article
Hit count: 316
In SICP exercise 2.26, this Scheme code is given:
(define x (list 1 2 3))
(define y (list 4 5 6))
Then this cons call is given:
(cons x y)
I expected a pair of lists would result, ((1 2 3) (4 5 6))
but the interpreter gives,
((1 2 3) 4 5 6)
...a list with 4 elements, the first being a list. Why is y treated differently? I've tried looking up other SICP answers for an explanation, but couldn't find something satisfactory. So could any Scheme/Lisp experts please shed some light on this aspect of cons? Thanks in advance for any insight.
© Stack Overflow or respective owner