[plt-scheme] Newbie question about Lisp
The answer Psy-Kosh gave applies equally to Lisp and to Scheme, and
for all flavors of those languages, as far as I know.
One way to see what's going on is to fire up DrScheme in "Beginning
Student" language. Type some expressions like:
(list 1)
(list 1 2)
(list 1 2 3)
See:
http://tinyurl.com/2htw6m
[ http://www.htdp.org/2003-09-26/Book/curriculum-Z-
H-13.html#node_sec_9.1 ]
See also the last paragraph of:
http://tinyurl.com/24c63h
[ http://www.htdp.org/2003-09-26/Companion/drscheme-Z-
H-3.html#node_chap_0 ]
To see that Common Lisp thinks of lists the same way, you could fire
up SBCL and try:
(cons 1 nil)
(cons 1 (cons 2 nil))
(cons 1 (cons 2 (cons 3 nil)))
but the (list 1), (list 1 2), (list 1 2 3) expansions in DrScheme's
Beginning Student language aren't available in SBCL because SBCL
doesn't have a beginning student language.
Lisp and Scheme are different in other ways. One example:
;; DrScheme, language: Beginning Student with List Abbreviations
(eq? #f '())
=> false
;; SBCL
(eq nil '())
=> T
Geoffrey
--
Geoffrey S. Knauth | http://knauth.org/gsk
On Apr 23, 2007, at 03:17, Psy-Kosh wrote:
> 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 list"
>
> 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?
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme