Is it a list ?
Thu Jul 10 22:19:48 CEST 2003
On Thu, 10 Jul 2003, Bjarne Däcker wrote:
> I think that this is a matter of history.
> Probably very early in Lisp they were
> more thinking in terms of binary trees
> ((1 . 2) . (3 . 4))
I strongly doubt it. I mean, yes, cons cells/pairs are for binary trees.
> which in Erlang would be
> [[1 | 2] | [3 | 4]]
> and then the idea of lists appeared
> (1 . (2 . (3 . (4 . nil))))
> and a special syntax evolved
> (1 2 3 4)
(Search for "To accomplish this McCarthy had to find a notation")
Binary tree is just one implementation of lists.
Cons cells are more generall just lists.
> but the "dotted pair" survived just
> like in English people say "geese"
> instead of "gooses".
> In Lisp you can write
> (1 2 3 4 . 5)
> which in Erlang becomes
> [1, 2, 3, 4 | 5]
> where the last element is not
>  or  but, in fact, simply 5.
> The space saving is negligeable
> but you could use this to write
> clever programs that others
> find difficult to understand.
Well, they also have some actually reasonable uses. E.g., association
The space savings is proportional to the length of the alist.
And, it's not merely a space optimization for circular lists:
Of course, whether one *should* use them is a different story. One debate:
Another more interesting one:
More information about the erlang-questions