Whats with the dot notation?

Discussion of Emacs Lisp

Whats with the dot notation?

Postby 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!
minibuffer
 
Posts: 5
Joined: Mon Feb 21, 2011 4:55 pm

Re: Whats with the dot notation?

Postby jstoddard » Wed Mar 09, 2011 3:31 pm

See http://www.gigamonkeys.com/book/they-called-it-lisp-for-a-reason-list-processing.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.
jstoddard
 
Posts: 20
Joined: Fri Jan 28, 2011 6:13 pm

Re: Whats with the dot notation?

Postby 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.
User avatar
Warren Wilkinson
 
Posts: 116
Joined: Tue Aug 10, 2010 11:24 pm
Location: Calgary, Alberta


Return to Emacs Lisp

Who is online

Users browsing this forum: No registered users and 3 guests