Whats with the dot notation?

Discussion of Emacs Lisp
Post Reply
minibuffer
Posts: 5
Joined: Mon Feb 21, 2011 4:55 pm

Whats with the dot notation?

Post by minibuffer » Wed Mar 09, 2011 2:05 pm

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!

jstoddard
Posts: 20
Joined: Fri Jan 28, 2011 6:13 pm

Re: Whats with the dot notation?

Post by jstoddard » Wed Mar 09, 2011 3:31 pm

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.

Warren Wilkinson
Posts: 117
Joined: Tue Aug 10, 2010 11:24 pm
Location: Calgary, Alberta
Contact:

Re: Whats with the dot notation?

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

Code: Select all


(cons 'first 'second)  ==> (first . second)
(cons 'first (list second)) ==> (first second)
Need an online wiki database? My Lisp startup http://www.formlis.com combines a wiki with forms and reports.

Post Reply