Why is cons-cell-notation infixed?

Whatever is on your mind, whether Lisp related or not.

Why is cons-cell-notation infixed?

Postby schoppenhauer » Sat Jan 30, 2010 4:04 pm

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?
Sorry for my bad english.
Visit my blog http://blog.uxul.de/
schoppenhauer
 
Posts: 99
Joined: Sat Jul 26, 2008 2:30 pm
Location: Germany

Re: Why is cons-cell-notation infixed?

Postby tkbits » Sat Jan 30, 2010 9:54 pm

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.
tkbits
 
Posts: 3
Joined: Sat Aug 02, 2008 8:15 pm
Location: USA

Re: Why is cons-cell-notation infixed?

Postby abu » Thu Feb 18, 2010 4:03 am

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.
abu
 
Posts: 7
Joined: Thu Feb 18, 2010 3:51 am
Location: Augsburg, Germany


Return to The Lounge

Who is online

Users browsing this forum: No registered users and 3 guests

cron