Announcements and discussions for Gnus, the GNU Emacs Usenet newsreader
 help / color / mirror / Atom feed
* what does '.' do in (visible . t)?
@ 2005-12-04 14:39 leon
  2005-12-04 14:51 ` Adam Sjøgren
  2005-12-04 15:07 ` Pascal Bourguignon
  0 siblings, 2 replies; 5+ messages in thread
From: leon @ 2005-12-04 14:39 UTC (permalink / raw)



Hi guys,

Here is an expression of lisp that I don't know what it means.
     (visible . t)

Could someone explain the function of '.' a bit?
Thanks in advance.

-- 
.:*~*:._.:*~*:._.:*~*:._.:*~*:._.:*~*:._.:*~*:.
.     *                                       .
.    /.\  excuses are the easiest things      .
.   /..'\     to manufacture                  .
.   /'.'\   and the hardest things to sell    .
.  /.''.'\                                    .
.  /.'.'.\                                    .
. /'.''.'.\                                   .
. ^^^[_]^^^                                   .
.                                             .
.Leon                                         .
.:*~*:._.:*~*:._.:*~*:._.:*~*:._.:*~*:._.:*~*:.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: what does '.' do in (visible . t)?
  2005-12-04 14:39 what does '.' do in (visible . t)? leon
@ 2005-12-04 14:51 ` Adam Sjøgren
  2005-12-04 15:03   ` leon
  2005-12-04 15:07 ` Pascal Bourguignon
  1 sibling, 1 reply; 5+ messages in thread
From: Adam Sjøgren @ 2005-12-04 14:51 UTC (permalink / raw)


On Sun, 04 Dec 2005 14:39:41 +0000, leon wrote:

> Here is an expression of lisp that I don't know what it means.
>      (visible . t)

> Could someone explain the function of '.' a bit?

I think it's in your elisp manual:
 <http://www.gnu.org/software/emacs/elisp-manual/html_node/elisp_26.html>


  Best regards,

-- 
 "Where hell waits behind every door                          Adam Sjøgren
  With John Denver songs"                                asjo@koldfront.dk


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: what does '.' do in (visible . t)?
  2005-12-04 14:51 ` Adam Sjøgren
@ 2005-12-04 15:03   ` leon
  0 siblings, 0 replies; 5+ messages in thread
From: leon @ 2005-12-04 15:03 UTC (permalink / raw)


Thanks.

asjo@koldfront.dk (Adam Sjøgren) writes:

 | On Sun, 04 Dec 2005 14:39:41 +0000, leon wrote:
 | 
 | > Here is an expression of lisp that I don't know what it means.
 | >      (visible . t)
 | 
 | > Could someone explain the function of '.' a bit?
 | 
 | I think it's in your elisp manual:
 |  <http://www.gnu.org/software/emacs/elisp-manual/html_node/elisp_26.html>
 | 
 | 
 |   Best regards,
 | 
 | -- 
 |  "Where hell waits behind every door                          Adam Sjøgren
 |   With John Denver songs"                                asjo@koldfront.dk


-- 
.:*~*:._.:*~*:._.:*~*:._.:*~*:._.:*~*:._.:*~*:.
.     *                                       .
.    /.\  excuses are the easiest things      .
.   /..'\     to manufacture                  .
.   /'.'\   and the hardest things to sell    .
.  /.''.'\                                    .
.  /.'.'.\                                    .
. /'.''.'.\                                   .
. ^^^[_]^^^                                   .
.                                             .
.Leon                                         .
.:*~*:._.:*~*:._.:*~*:._.:*~*:._.:*~*:._.:*~*:.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: what does '.' do in (visible . t)?
  2005-12-04 14:39 what does '.' do in (visible . t)? leon
  2005-12-04 14:51 ` Adam Sjøgren
@ 2005-12-04 15:07 ` Pascal Bourguignon
  2005-12-04 15:12   ` leon
  1 sibling, 1 reply; 5+ messages in thread
From: Pascal Bourguignon @ 2005-12-04 15:07 UTC (permalink / raw)


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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: what does '.' do in (visible . t)?
  2005-12-04 15:07 ` Pascal Bourguignon
@ 2005-12-04 15:12   ` leon
  0 siblings, 0 replies; 5+ messages in thread
From: leon @ 2005-12-04 15:12 UTC (permalink / raw)


Pascal Bourguignon <spam@mouse-potato.com> writes:

 | 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

Thank you for this wonderful explanation:-)

-- 
.:*~*:._.:*~*:._.:*~*:._.:*~*:._.:*~*:._.:*~*:.
.     *                                       .
.    /.\  excuses are the easiest things      .
.   /..'\     to manufacture                  .
.   /'.'\   and the hardest things to sell    .
.  /.''.'\                                    .
.  /.'.'.\                                    .
. /'.''.'.\                                   .
. ^^^[_]^^^                                   .
.                                             .
.Leon                                         .
.:*~*:._.:*~*:._.:*~*:._.:*~*:._.:*~*:._.:*~*:.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-12-04 15:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-04 14:39 what does '.' do in (visible . t)? leon
2005-12-04 14:51 ` Adam Sjøgren
2005-12-04 15:03   ` leon
2005-12-04 15:07 ` Pascal Bourguignon
2005-12-04 15:12   ` leon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).