Page 1 of 1

Why is cons-cell-notation infixed?

Posted: Sat Jan 30, 2010 4:04 pm
by schoppenhauer
There is something I always wondered ... Since in most cases Lisp prefers prefixed notations, why are cons-cells written in the form (A . B), which is an infix-notation as far as I see. Of course, when parsing a list, and creating its data structure, this notation does not really make the situation more complicated, since you could just read the next symbol, and then - if its not the dot - push a new cons cell on the cdr of the current one and set its car to the symbol, and if the list ends set the cdr to nil, if its a dot, push it, and set the cdr to the value given after the dot. And I see that this notation is handy when specifying lists which do not end in nil, like in scheme's define-statements for arbitrary many additional arguments.

I dont consider this a bad thing, I just always wondered why we have an infix notation here, while avoiding it on vitally every other place. Has it some historical reasons?

Re: Why is cons-cell-notation infixed?

Posted: Sat Jan 30, 2010 9:54 pm
by tkbits
The "infix" dot notation has certainly been there at the start.

You might want to check out McCarthy's 1960 article at

http://www-formal.stanford.edu/jmc/recursive.html

Note the historical use of commas as separators in proper lists. The dot notation is probably a parallel to the commas, allowing symbolic atoms to use embedded spaces without escape mechanisms (such as slashification).

It might be noted that Lisp 1.5 supported both commas and spaces as separators, by making commas equivalent to a space.

Re: Why is cons-cell-notation infixed?

Posted: Thu Feb 18, 2010 4:03 am
by abu
You have to be aware of the fact that the cons-cell-notation is a matter of
S-expressions, not of Lisp code.

The parentheses and the dot are meta-characters that describe the structure of
data, and are on a lower level than the executable code they might represent.
S-expressions by themselves are neither pre-, in- or postfix.

As (A . B) represents a single cell

Code: Select all

   +-----+-----+
   |  A  |  B  |
   +-----+-----+
it might indeed make sense to write it as (. A B)

But then (as you noted), what to do then with a structure like (A B C . D)

Code: Select all

   +-----+-----+     +-----+-----+     +-----+-----+
   |  A  |  ---+---> |  B  |  ---+---> |  C  |  D  |
   +-----+-----+     +-----+-----+     +-----+-----+
How would we denote that?

On the other hand, we could even say that the dot is a kind of prefix
notation, where the following expressions (here 'D') is to be stored in the CDR
part of the last cell.