Page 1 of 1

Whats with the dot notation?

Posted: Wed Mar 09, 2011 2:05 pm
by minibuffer
Can someone please explain me what is the dot notation in lists:

Code: Select all

(first . second)
Why not just:

Code: Select all

(first second)
Thanks!

Re: Whats with the dot notation?

Posted: Wed Mar 09, 2011 3:31 pm
by jstoddard
See http://www.gigamonkeys.com/book/they-ca ... ssing.html

It's a Common Lisp book, not an Emacs Lisp book, but I think the concepts more or less apply. Basically (a . b) is called a cons cell -- a is the "car" and b is the "cdr". The cdr tends to be a pointer to another cons cell, making a list. That is, if b is a pointer to (c . d) and d is a pointer to (e . nil), you get (a . (c . (e . nil))), which can be displayed in list form as (a c e). The simple graphics in the link above really help for visualizing what's going on.

Re: Whats with the dot notation?

Posted: Wed Mar 09, 2011 9:03 pm
by Warren Wilkinson

Code: Select all


(cons 'first 'second)  ==> (first . second)
(cons 'first (list second)) ==> (first second)