[plt-scheme] The role of proper and improper lists?

From: Grant Rettke (grettke at acm.org)
Date: Thu Jan 24 22:24:07 EST 2008

I'm working on the problems in
_The_Scheme_Programming_Language_3rd_Edition and I came upon a problem
that made me think about improper lists. The thing about which I was
wondering was when you would use an improper list rather than a proper
list. A simple contrived example about which I was thinking.

Suppose you got a list of key-pair values. You could assemble it, for
example, in one of the two ways:

(list (list 'a 1) (list 'b 2) (list 'b 3))

or

(list (cons 'a 1) (cons 'b 2) (cons 'c 3))

when you grab one of the key-pair values you could retrieve the key
and the pair with

(car (list 'a 1))
(cadr (list 'a 1))

for the former or

(car (cons 'a 1))
(cdr (cons 'a 1))

So there are two ways of doing... the same thing? Is it the same?

An improper list is *not* terminated with the empty list, a proper
list is terminated:

(cons 1 2)

versus

(cons 1 (cons 2 '()))

Where/when/why does this matter?


Posted on the users mailing list.