From: Software Scavenger
Subject: dot
Date: 
Message-ID: <a6789134.0111020354.5886631d@posting.google.com>
Is '(a b c . (d e f)) ever a useful notation?  To me it seems like
saying (= (+ 002 002) 00004).  But the Hyperspec mentions it and gives
the vague impression that it might be useful for something.  I.e.,
that it might have some value other than 00000.

From: Tim Bradshaw
Subject: Re: dot
Date: 
Message-ID: <ey3u1wd9w5y.fsf@cley.com>
* Software Scavenger wrote:
> Is '(a b c . (d e f)) ever a useful notation?  To me it seems like
> saying (= (+ 002 002) 00004).  But the Hyperspec mentions it and gives
> the vague impression that it might be useful for something.  I.e.,
> that it might have some value other than 00000.

It's useful if what you want to do is reason about what the structure
is, for instance if it's really not a list but something else.

For instance (if you read my article on strentgh of boolean
combinations), my features have aliases and there is a list which maps
from aliases to feature & strength, and its structure is:

	(alias . (canonical-feature . strength))

of course this is just the same as 

	(alias canonical-feature . strength)

but the former notation gets across the intended structure - namely a
map from names to pairs - much better.

(Of course I never actually write any entries by hand into the list -
there's a feature-defining macro, but somewhere in its guts it says:

	(push '(,alias .  (,canonical-name . ,strength)) ...)

)

--tim	
From: Kent M Pitman
Subject: Re: dot
Date: 
Message-ID: <sfwzo65z1f8.fsf@world.std.com>
··········@mailandnews.com (Software Scavenger) writes:

> Is '(a b c . (d e f)) ever a useful notation?  To me it seems like
> saying (= (+ 002 002) 00004).  But the Hyperspec mentions it and gives
> the vague impression that it might be useful for something.  I.e.,
> that it might have some value other than 00000.

Well, you have to know it works that way partly so you can explain to
people that (c . ()) is the structure of (c).  and so you can explain
that (a . (b . (c . ()))) is the structure of (a b c).  It's visually
useful.

When you do (cons 'a 'b) you get (a . b) and you will see the dot.
You have to understand why (cons 'a '(b c)) doesn't show you 
(a . (b c)) and the answer is that it *does* show  you (a . (b c))
but that these are equivalent notations.  Just as sometimes it's
"useful" to write 1.0 as 1.0000 even though it adds no information,
it can be useful to create visual regularity in some pattern you
are trying to make visually in your code.  For example:


 (defvar *my-alist* '((symbol . seven)
                      (number . 7)
                      (list   . (1 2 3 4 5 6 7))))

It would be more confusing to have to write this as:

 (defvar *my-alist* '((symbol . seven)
                      (number . 7)
                      (list   1 2 3 4 5 6 7)))

if you were not allowed to use the dot notation.

Further, the circularity detector will sometimes use this notation and
you may have reason to use it yourself.

 #1=(A . #1#)

is the canonical printed form of a circular list having only A as its
element, but you might see this printed as (A A A A ...) if *PRINT-CIRCLE*
is NIL but *PRINT-LENGTH* is 4.

Does any of this help?
From: Software Scavenger
Subject: Re: dot
Date: 
Message-ID: <a6789134.0111021313.6f65f50d@posting.google.com>
Kent M Pitman <······@world.std.com> wrote in message news:<···············@world.std.com>...

> Does any of this help?

Yes, that's a good explanation.  I was just curious to know why people
used such notation and thought I might be missing something subtle. 
Thanks.
From: Pierre R. Mai
Subject: Re: dot
Date: 
Message-ID: <878zdp879c.fsf@orion.bln.pmsf.de>
··········@mailandnews.com (Software Scavenger) writes:

> Is '(a b c . (d e f)) ever a useful notation?  To me it seems like
> saying (= (+ 002 002) 00004).  But the Hyperspec mentions it and gives
> the vague impression that it might be useful for something.  I.e.,
> that it might have some value other than 00000.

The notation in question is particularly helpful when describing lists
with shared components, especially tails.  This is e.g. helpful in
defpackage forms.  In the following example we define an "internal"
package, that is intended for use by packages extending the system,
and an "external" package, that only exports those symbols which are
intended for normal programmers, who are only intending to use the
library in question:

(eval-when (:compile-toplevel :load-toplevel :execute)
(defpackage #:maisql-sys
    (:nicknames #:sql-sys)
    (:use #:common-lisp)
    (:export
     ;; "Private" exports for use by interface packages
     #:check-connection-spec
     #:database-type-load-foreign
     ;; ... ETC ...
     #:database-dump-result-set
     #:database-store-next-row
     ;; Shared exports for re-export by MAISQL
     .
     #1=(#:maisql-condition
	 #:maisql-error
	 #:maisql-simple-error
         ;; ... ETC ...
	 #:insert-records
	 #:delete-records
	 #:update-records
	 #:with-database))
    (:documentation "This is the INTERNAL SQL-Interface package of MaiSQL."))

(defpackage #:maisql
    (:nicknames #:sql)
    (:import-from #:maisql-sys . #1#)
    (:export . #1#)
    (:documentation "This is the SQL-Interface package of MaiSQL."))
);eval-when


Note the use of the dotted list notation in combination with the
circular data notation in the :export and :import-from clauses of both
defpackage forms  [Aside:  the defpackage forms are wrapped inside one
top-level form to enable the use of #1= and #1# across both forms]

There are of course other ways of achieving that (e.g. #. read-time
evaluation), but the above form is far more direct and readable IMHO.

Regs, Pierre.

-- 
Pierre R. Mai <····@acm.org>                    http://www.pmsf.de/pmai/
 The most likely way for the world to be destroyed, most experts agree,
 is by accident. That's where we come in; we're computer professionals.
 We cause accidents.                           -- Nathaniel Borenstein
From: Kaz Kylheku
Subject: Re: dot
Date: 
Message-ID: <rJEE7.4908$Ud.112678@news1.rdc1.bc.home.com>
In article <····························@posting.google.com>, Software
Scavenger wrote:
>Is '(a b c . (d e f)) ever a useful notation?  To me it seems like
>saying (= (+ 002 002) 00004).  But the Hyperspec mentions it and gives
>the vague impression that it might be useful for something.  I.e.,
>that it might have some value other than 00000.

With two elements, the dot notation is the written convention for
representing a cons cell. For example,

	(1 . 2)

represents, in writing, a cons cell object consisting of the atoms 1
and 2. That is, the CAR is 1, and the CDR is 2.

This is different from the following notation for a list object

	(1 2)

which represents an object made up of TWO cons cells. The first cons
cell has a CAR field of 1, and a CDR field which is a reference to the
second cons cell. The second cons cell has a CAR of 2, and a CDR of NIL.

In general, any list

	(gamma)

where gamma is any non-empty sequence of objects, can be written using
the dot notation

	(gamma . NIL)

which merely makes the NIL termination of the list explicit.

Your Lisp system won't use that representation when printing that object
back to you; it will only choose the dot representation when the CDR field
of the terminating cons cell is an atom other than NIL. So if you type

	'(1 . NIL)

you will get back

	(1)

From this you can infer the equivalence of (a b c . (d e f))
and (a b c d e f).

Dotted pairs are useful when you need to represent pairs of things
in an efficient way. E.g. an association list:

	(assoc :haircolor '((:height . 185) 
                            (:weight . 85)
                            (:haircolor . :brown)
                            (:age . 39)))

	==> (:haircolor . :brown)

Such a list uses fewer cons cells, and access to the associated
property is perhaps slightly faster, since there is one less pointer
to chase.

So you see it's not that the dot *notation* is useful, per se, but the
special objects that it can be used to denote. Whereas 00001 does not
denote anything different from 1.

Incidentally, the . element is also permitted in destructuring lambda
lists---the parameter lists used by macros and destructuring-bind. That
is, you can write, for instance:

	(defmacro m (a . b) ...)

In this context, the dot has a meaning similar to &rest; the first
argument is bound to a remaining arguments are are spun into a list
bound to b. However, no &key or &aux parameters are allowed after that.

This notation within the macro lambda list is useful syntactic sugar when
you want to write a macro which is specifically intended for matching a
dotted pair. The definition of the macro then neatly resembles its use,
which clarifies its purpose.