[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SEQUENCES



    Despite pooh-poohing of efficiency, I consider it extremely important.
    Generic operations are hard to compile without a clever compiler AND
    declarations.

I didn't mean to give the impression I was pooh-poohing efficiency when
I brought up Smalltalk.  On the contrary -- I was saying that generic
operations were very difficult to implement well.  My point was only that
Common Lisp might not have come up with a very good set of generic
operations precisely because efficiency was important.

    I have never felt the slightest need for a "sequence" abstraction,
    and it certainly isn't going to clarify my thoughts for CAR, LENGTH,
    et al.  to be forced to be about this new abstraction.

[This sounds like a person defending his favorite line editor against
the onslaught of screen editors.] Seriously, the lack of "feeling a need"
does not necessarily mean that a new idea is not worthwhile.  Perhaps
your lack of "need" is due to the fact that no existing efficient language
has provided a decent set of generic operations.

I, on the other hand, have felt a distinct need for generic operations
on sequences BECAUSE I've been concerned for efficiency.  How many times
in Bliss, C, or Lisp have I chosen a vector to implement a sequence for
efficiency, only to find out some other package used linked lists?  Or
vice versa?  How many times have I needed to change a sequence
implementation because of new constraints or because I am pick-putting
some old code?  How many times have I had to edit every single reference
to a data structure just because I changed the sequence implementation?
How many times have I gotten burned because I wanted to change the bounds
of a vector, but forgot to track down every single loop that enumerated
through that vector?  I've done an awful lot of such editing, all in the
name of efficiency.

Think how much cleaner and compact your code would be if there was only
one small set of primitives for accessing all the different kinds of
sequences.  And don't forget control structures -- just imagine if all
your sequence-enumerating loops looked like

    (loop (for element in sequence) ...

instead of

    (loop (incr i from 1 to array-size)
          (next element (array i) )
          ...

    (loop (for element in list) ...

    (loop (incr i from 1 to (string-length string) )
          (next char (nth-char string i) )

    etc.

One of the reasons that the Smalltalk system is relatively compact and
elegant is because of the code-sharing resulting from well-thought-out
generic operations.  A trivial example is printing a sequence -- one piece
of code will suffice for each different flavor of sequence.  I for one
am not going to dismiss the real advantages of a language like Smalltalk
just because we don't have a good idea how to implement them as efficiently
as we would want.  Smalltalk is not perfect, but surely we can learn from
other languages?

We all recognize that it is a hard problem to implement generic operations
well enough to be efficient compared with non-polymorphic, type-declared
lanaguages (including T).  And maybe now is not the time to introduce
them into T.  But these considerations in no way reflect on the ultimate
usefulness of generic operations.

    A spiel I have delivered before:  A language succeeds because of the
    abstractions built into it.  LISP has succeeded because of lists,
    and T must retain this orientation.  I sense that some are ashamed
    of these things, or feel they are old fashioned.  Practice feeling
    proud of list structures.  If someone asks what you are doing, don't
    say "AI research," or "Building abstractions," say, "CONSing list
    structure, and proud of it!"

I don't think anyone is ashamed of consing lists in Lisp.  Lisp lists
are useful exactly because we don't have generic operations; Lisp lists
provide a uniformly-accessed data structure that is moderately efficient
for many applications.  If I had to pick a single data structure, I too
would pick Lisp lists.  But lists are not enough (for Jacqueline Suzanne)
-- witness the need for vectors in every variety of modern Lisp.  Once
we concede the need for different data structures, how do we best make
use of them?
-------