Why does using cons to create a pair of two lists produce a list and two elements?
Posted
by fingerprint211b
on Stack Overflow
See other posts from Stack Overflow
or by fingerprint211b
Published on 2010-06-11T11:59:36Z
Indexed on
2010/06/11
12:02 UTC
Read the original article
Hit count: 190
I've started learning Scheme, for fun mostly, and because I've never used a functional language before. I chose Scheme because I wanted to read SICP for a long time.
Anyway, I'm currently learning about lists, and before that I learned about cons, car and cdr. And there's an example that creates a list of lists with cons, like this :
(cons (list 1 2) (list 3 4))
The resulting list is ((1 2) 3 4), which doesn't make sense to me, I would expect ((1 2)(3 4)) to be the result (a list made out of two lists). Why does it behave like that? I realize that if I were to use car, I would get (1 2), and cdr I'd get (3 4) becaue cdr always returns "the rest", but I don't understand why the list isn't made of two lists?
© Stack Overflow or respective owner