[plt-scheme] Newbie question about Lisp

From: Psy-Kosh (psykosh at earthlink.net)
Date: Mon Apr 23 03:17:01 EDT 2007

On Sun, 22 Apr 2007 14:49:07 -0400, Greg Akins <angrygreg at gmail.com> wrote:

> I have question about Lisp (Common Lisp, not Scheme).
> Does anyone object to me asking here?  If so, can someone recommend a
> better list.
> I looked into comp.lang.lisp, but it appeared to have a lot of
> traffic, and not many newcomers.
> The questions is :
> Why the "." in evaluating (cons 1 2)
> returns (1 . 2)
> But (list 1 2)
> returns (1 2)

Well, that's an issue about the fundumental nature of what a list is.

The fundumental object here is the pair aka dotted pair, aka cons cell.

(1 2 3) is really just a shorthand for (1 . (2 . (3 . ())))

ie, a cons cell can hold two values. In a basic linked list, what one does  
is have the first value be, well, a member of the list, and the second  
value is another cons cell. ie, the "rest of the list"

the value () is a special thing, not a cons cell, but the "empty list".

ie, think of it this way. internally a pair is something that's got two  
pointers. in a proper list, the second pointer always is to another cons  
cell or to the empty list. In other words, each pair basically says  
"here's my value, and over there is where you can find the rest of the  

cons constructs a pair. (cons 1 2) simply produces a pair containing 1 and  
2. list organizes stuff into a list structure.

(list 1 2 3) effectively does this: (cons 1 (cons 2 (cons 3 '())))

That help?

Posted on the users mailing list.