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

function names.

    Date: Tue, 26 Mar 85 10:00:27 est
    From: linus!ramsdell (John D. Ramsdell)
    Message-Id: <8503261500.AA09753@linus.UUCP>
    Subject: function names.

    It is clear no agreement can be reached about CAR and CDR.
    I withdraw the suggested name changes except for:
    MAPCAR  =>  MAP and
    MAPC    =>  WALK.
    Is there disagreement here?

I support these name changes (perhaps not surprisingly since
I'm partly responsible for them being that way in T). For those
who are curious about the justification for the MAPCAR->MAP change:

 * MAP is nicely generic. You can't later extend MAPCAR to
   work on general structures like matrices without having to
   apologize for the fact that "successive cars of a matrix"
   is not as meaningful as it is for lists.

 * Whenever anyone complained to me that MAP had another 
   meaning and that people would be confused, I would take
   them by the arm and drag them into the office of an
   unsuspecting person to whom I would say: "Please write
   an expression on the board which maps a function F across
   a list L." The person would -always- write
     (MAPCAR F L)
   No one -ever- wrote
     (MAP F L)
   The reason is that MAP is so uncommon that no one even 
   bothers to verbally distinguish it from MAPCAR. You have to
   say "Please write an expression which calls the function MAP
   on arguments which are the function F and the list L." to get
   the other behavior. From this I conclude that it is "natural"
   for the MAPCAR operation to be called MAP.

The arguments for MAPC->WALK are these:

  MAPCAR returns a value which is     intended to be used.
  MAPC   returns a value which is not intended to be used.

  MAPCAR takes a function which is not intended to have a side-effect.
  MAPC   takes a function which is     intended to have a side-effect.

  These two functions have little more in common than the fact
  that their first arg is a function and the second is a list.

  Also, the "C" is pretty random (presumably deriving from the "CAR"
  in MAPCAR). As with MAPCAR, if MAPC were ever extended to map across
  (notice I'm using the word "map" and you -know- what I mean) matrices,
  arrays, vectors, etc. then again the "C" would be still harder to

  So we wanted something that connoted `visiting elements' but not 
  a priori constraining the way those elements were enumerated and
  not connoting any idea of return value. WALK was chosen because it's
  short, sounds like what it does ("walks around in structures"), etc.

By the way, T uses MAPCDR and WALKCDR to mean the "less common" variants
(MAPLIST and MAP, respectively, so you don't have to look them up). The
fact that the names are longer is appropriate (common things should get
the short names), as is the fact that the term CDR is included (since
these don't make sense to generalize to non-CDRable things (although if
you generalized CDR, they would make sense and their name would still
be fine)).

To help with this convention, T renames Lisp's traditional LAST function
to LASTCDR, so what is sometimes called LASTCAR can be called LAST (for
naming consistency with MAP/MAPCDR, WALK/WALKCDR, NTH/NTHCDR).

It is this sort of regularization of naming which has led users of T to
spontaneously send fan mail saying how much they like the clarity of
expression the new names encourage. (Most other languages I've seen get
mostly gripes about naming and little or no praise.) What gripes we get
are usually nitpicky things where users (having decided things are really
winning) want to encourage us to go the rest of the way toward making
the naming consistent in the places where we hesitated to make choices
which would clearly have made the language even more regular. Almost no
one has complained of missing an old name (especially since for the cases
where they care, it's so easy to define synonyms).