Yi DAI scripsit:

> Why do we have both list and dotted-list, given that the former is just a
> special case (terminated by nil) of the latter? Can we simply live with the
> latter?

Conceptually, lists are the basic functional programming data structure:
sequential with O(n) access and shareable (in Lisp/Scheme, also mutable).
For historical reasons, lists are not primitive in Scheme but are
implemented using pairs, and this fact is exposed to Scheme programmers.

Dotted-lists are basically an artifact of that implementation strategy.
In statically typed functional languages like ML or Haskell, they are
not permitted.  Even in Lisp/Scheme, they are not often used (even the
use of plain pairs is relatively uncommon except in a-lists).

> I see it is fairly easy to write common list procedures, like
> `length', `map', `append' etc that could handle dotted-list very well, with
> the predicate `pair?'. 

Not so much.  Map and append operate on every element of a list, but
is the dotted element of a list part of it or not?  What is the proper
value of (append '(a b . c) '(d e . f))?  Not (a b . c d e . f), for
that is meaningless.

In Common Lisp there is a predicate "endp" (which would be spelled "end?"
in Scheme) that returns true on (), false on a pair, and signals an
error on any other argument.  It's convenient for dealing with lists
element by element that should not be dotted but still might be.

-- 
With techies, I've generally found              John Cowan
If your arguments lose the first round          http://www.ccil.org/~cowan
    Make it rhyme, make it scan                 co...@ccil.org
    Then you generally can
Make the same stupid point seem profound!           --Jonathan Robie

_______________________________________________
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users

Reply via email to