info-gnus-english
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: what does '.' do in (visible . t)?


From: Pascal Bourguignon
Subject: Re: what does '.' do in (visible . t)?
Date: Sun, 04 Dec 2005 16:07:44 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

leon <sdl.web@gmail.com> writes:
> Here is an expression of lisp that I don't know what it means.
>      (visible . t)
>
> Could someone explain the function of '.' a bit?

This is the notation for the basic structure named cons (or pair in
scheme), which contains two fields: one named cdr and another named
car.  Conses can be allocated and initialized with (cons car cdr).
Conses are printed (and can be read back) with the format:

      ( car . cdr )

(cons 'a 'b) --> (a . b)


Now, since in lisp we use conses to build lists, putting an element in
the car, and the rest of the list in the cdr (which can be another
cons, or the symbol nil, indicating the end of the list), the printer
writes conses specially when their cdr contains another cons.

A list containing the symbols a, b, c, and d, can be built with:

      (cons 'a (cons 'b (cons 'c (cons 'd nil))))

this is what the function list does: (list 'a 'b 'c 'd) executes the
above cons function calls.

It could be printed as:

      (a . (b . (c . (d . nil))))


With:

(defun print-conses (x)
   (if (consp x)
       (progn (princ "(")
              (print-conses (car x))
              (princ " . ")
              (print-conses (cdr x))
              (princ ")"))
       (princ x)) 
    x)

(print-conses (cons 'a (cons 'b (cons 'c (cons 'd nil)))))

prints:

    (a . (b . (c . (d . nil))))

But since conses are often used to store lists, the printer prints
them by default as:

    (a b c d)


(print (cons 'a (cons 'b (cons 'c (cons 'd nil)))))

Prints:

    (a b c d)



Finally, if the last cons of a list contains another atom than nil in
the cdr, it's not a proper list, and print prints a dot to indicate
this, followed by the cdr, instead of eliding the nil:

(print (cons 'a (cons 'b (cons 'c (cons 'd 'e)))))

Prints:

    (a b c d . e)




Note: for all x, (eq (not (consp x)) (atom x))
-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Our enemies are innovative and resourceful, and so are we. They never
stop thinking about new ways to harm our country and our people, and
neither do we. -- Georges W. Bush


reply via email to

[Prev in Thread] Current Thread [Next in Thread]