From: Jeremy Whetzel
Subject: 'first and rest' or 'car and cdr'
Date: 
Message-ID: <867kqg33oe.fsf@buddha.home>
Hi,

I'm new to lisp and very interested in learning CL.  This may be a
nitpick sort of question, but I was reading in "Lisp 3rd Edition" by
Watson and Horn, and I noticed that it says that using 'car' and 'cdr'
are no longer commonly used, and have been, for the most part, replaced
with 'first' and 'rest'.  I haven't been around on the list long, but in
most tutorials and examples, I thought I saw car and cdr used more
often.  Is there any difference in using one or the other, or is it
mainly just a question of style?

Thanks,
Jeremy

From: Thomas F. Burdick
Subject: Re: 'first and rest' or 'car and cdr'
Date: 
Message-ID: <xcvn0zciana.fsf@famine.OCF.Berkeley.EDU>
Jeremy Whetzel <·····@toadmail.com> writes:

> Hi,
> 
> I'm new to lisp and very interested in learning CL.  This may be a
> nitpick sort of question, but I was reading in "Lisp 3rd Edition" by
> Watson and Horn, and I noticed that it says that using 'car' and 'cdr'
> are no longer commonly used, and have been, for the most part, replaced
> with 'first' and 'rest'.  I haven't been around on the list long, but in
> most tutorials and examples, I thought I saw car and cdr used more
> often.  Is there any difference in using one or the other, or is it
> mainly just a question of style?

Others have already answered this, but I'll chime in as someone who
actually uses first and rest.  It makes it easier to see what I was
thinking when I wrote the code.  CAR and CDR mean I was thinking in
terms of cons cells.  So I need to worry about the structure of
something made out of pairs of pointers.  FIRST and REST mean that I
was thinking about lists, and needn't worry my pretty head about where
pointers are pointing.  Plus, rest is nicely like &rest.

I do understand both perfectly, and it's important to (including all
the c***r variants).  One way to implement a queue in Lisp is to have
a list containing all the elements in the queue, and have a single
cons cell that points to the head and the tail.  You append to the
tail of the queue with:

  (defun append-to-queue (thing queue)
    (let ((new-elt (list thing)))
      (setf (cddr queue) new-elt
            (cdr queue) new-elt)))

I'd be kind of annoyed if someone wrote that with (rest (rest queue))
and (rest queue).  That would *work*, but it implies that you're working
on a list, which, in this case, isn't true.

-- 
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                               
   |     ) |                               
  (`-.  '--.)                              
   `. )----'                               
From: Steven M. Haflich
Subject: Re: 'first and rest' or 'car and cdr'
Date: 
Message-ID: <3C47B7F6.A8F40E78@pacbell.net>
"Thomas F. Burdick" wrote:

> I do understand both perfectly, and it's important to (including all
> the c***r variants).  One way to implement a queue in Lisp is to have
> a list containing all the elements in the queue, and have a single
> cons cell that points to the head and the tail.  You append to the
> tail of the queue with:
> 
>   (defun append-to-queue (thing queue)
>     (let ((new-elt (list thing)))
>       (setf (cddr queue) new-elt
>             (cdr queue) new-elt)))

I wonder that you didn't write

    (defun append-to-queue (thing queue)
      (let ((new-elt (list thing)))
        (setf (reest queue) new-elt
              (rest queue) new-elt)))

and similarly elsewhere "fiirst" and "fiiirst" and "reeest".
The obvious problem comes when it is necessary to compound
idiomatic names that are not either hyper-dexter or
hyper-sinister.  Perhaps "reirst" for cdar and "firest" for cadr?
Although these names are not as easy to remember as c*r, the
fortunate coincidence that "first" and "rest" both end in "st"
will make these functions easy to recognize, e.g. "fireirst".

> I'd be kind of annoyed if someone wrote that with (rest (rest queue))
> and (rest queue).  That would *work*, but it implies that you're working
> on a list, which, in this case, isn't true.
From: Thomas F. Burdick
Subject: Re: 'first and rest' or 'car and cdr'
Date: 
Message-ID: <xcvofjpvl1g.fsf@conquest.OCF.Berkeley.EDU>
"Steven M. Haflich" <·······@pacbell.net> writes:

> "Thomas F. Burdick" wrote:
> 
> > I do understand both perfectly, and it's important to (including all
> > the c***r variants).  One way to implement a queue in Lisp is to have
> > a list containing all the elements in the queue, and have a single
> > cons cell that points to the head and the tail.  You append to the
> > tail of the queue with:
> > 
> >   (defun append-to-queue (thing queue)
> >     (let ((new-elt (list thing)))
> >       (setf (cddr queue) new-elt
> >             (cdr queue) new-elt)))
> 
> I wonder that you didn't write
> 
>     (defun append-to-queue (thing queue)
>       (let ((new-elt (list thing)))
>         (setf (reest queue) new-elt
>               (rest queue) new-elt)))
> 
> and similarly elsewhere "fiirst" and "fiiirst" and "reeest".

I think you missed my point.  I think c***r are great for manipulating
cons cells.  I use first, second, ..., rest when thinking in terms of
lists, primarily as a tip off to myself when reading my code later.
CADAR says "picture cells and pointers and stuff".  THIRD says "think
about a list".  I have no beef with c***r.

-- 
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                               
   |     ) |                               
  (`-.  '--.)                              
   `. )----'                               
From: Nils Goesche
Subject: Re: 'first and rest' or 'car and cdr'
Date: 
Message-ID: <a27qfp$uvrs3$1@ID-125440.news.dfncis.de>
In article <··············@buddha.home>, Jeremy Whetzel wrote:

> I'm new to lisp and very interested in learning CL.  This may be a
> nitpick sort of question, but I was reading in "Lisp 3rd Edition" by
> Watson and Horn, and I noticed that it says that using 'car' and 'cdr'
> are no longer commonly used, and have been, for the most part, replaced
> with 'first' and 'rest'.  I haven't been around on the list long, but in
> most tutorials and examples, I thought I saw car and cdr used more
> often.  Is there any difference in using one or the other, or is it
> mainly just a question of style?

Purely a style question.  Some people use car and cdr when accessing
cons cells that are not part of a list, and first and rest otherwise.
Others, like me, never use first or rest.  It's entirely up to you :-)

Regards,
-- 
Nils Goesche
"Don't ask for whom the <CTRL-G> tolls."

PGP key ID 0x42B32FC9
From: Matthieu Villeneuve
Subject: Re: 'first and rest' or 'car and cdr'
Date: 
Message-ID: <3C477B80.B188F0D2@tumbleweed.com>
Jeremy Whetzel wrote:
> 
> Hi,
> 
> I'm new to lisp and very interested in learning CL.  This may be a
> nitpick sort of question, but I was reading in "Lisp 3rd Edition" by
> Watson and Horn, and I noticed that it says that using 'car' and 'cdr'
> are no longer commonly used, and have been, for the most part, replaced
> with 'first' and 'rest'.  I haven't been around on the list long, but in
> most tutorials and examples, I thought I saw car and cdr used more
> often.  Is there any difference in using one or the other, or is it
> mainly just a question of style?

I would say it's only a question of style. Your program can be easier to
understand if you use first and rest (and second, third,...) whenever
you are accessing elements of a list, car and cdr (and cadr, caar,...)
otherwise.

--Matthieu
From: Kaz Kylheku
Subject: Re: 'first and rest' or 'car and cdr'
Date: 
Message-ID: <piL18.10028$467.397745@news2.calgary.shaw.ca>
In article <··············@buddha.home>, Jeremy Whetzel wrote:
>
>Hi,
>
>I'm new to lisp and very interested in learning CL.  This may be a
>nitpick sort of question, but I was reading in "Lisp 3rd Edition" by
>Watson and Horn, and I noticed that it says that using 'car' and 'cdr'
>are no longer commonly used, and have been, for the most part, replaced
>with 'first' and 'rest'.  I haven't been around on the list long, but in
>most tutorials and examples, I thought I saw car and cdr used more
>often.  Is there any difference in using one or the other, or is it
>mainly just a question of style?

It's a question of style. The names first and rest suggest that you are
working with a list. So when working with lists, it makes sense to use
first and rest. If you are working with cons cells that are being used
to represent pairs, then these names don't make as much sense. Say you
have the pair (3 . 5) would you call 5 ``rest''?  It's up to you.
From: Kenny Tilton
Subject: Re: 'first and rest' or 'car and cdr'
Date: 
Message-ID: <3C478452.15331CD7@nyc.rr.com>
Jeremy Whetzel wrote:
>  I thought I saw car and cdr used more
> often.  Is there any difference in using one or the other, or is it
> mainly just a question of style?

style and personal pref.

i use car and cdr, makes me feel macho. i find it funny they are machine
instructions, i love the historical feel, like El Duque of the Yankees
wearing knee-high trousers.

i also feel it's good to think in terms of the cons cell without the
syntactic (or in this case mere terminological) sugar which mask
reality.

kenny
clinisys
From: Christopher Stacy
Subject: Re: 'first and rest' or 'car and cdr'
Date: 
Message-ID: <upu48bd4i.fsf@spacy.Boston.MA.US>
>>>>> On 17 Jan 2002 19:26:09 -0500, Jeremy Whetzel ("Jeremy") writes:
 Jeremy> I'm new to lisp and very interested in learning CL.  This may
 Jeremy> be a nitpick sort of question, but I was reading in "Lisp 3rd
 Jeremy> Edition" by Watson and Horn, and I noticed that it says that
 Jeremy> using 'car' and 'cdr' are no longer commonly used, and have
 Jeremy> been, for the most part, replaced with 'first' and 'rest'.

Yes, they suggest that "Some old-timers use CAR and CDR".

I think this is a case of the authors trying to inflict their personal
style on unsuspecting readers, starting a new trend, perhaps because
they believed that it would help make Lisp more popular by seeming to
have outgrown those historical artifacts.  That viewpoint is not at all
unreasonable from a new-language design point of view.  It is possible
that they were misinformed, but I was in close proximity a few years
before that book was published, and I doubt that was the case.
I suspect it was a deliberate attempt at manipulation with good motives.
In any event, I don't believe that they were stating a true fact about
the way most people wrote Lisp code in the late 1980s.  
Or today, for that matter. I think most people still call CAR and CDR.

If you prefer to use FIRST and REST in your code, more power to you.
You will still have to read code written by other people that contains
CAR and CDR, however, and you are liable to see CAR and CDR appearing 
in stack backtraces when debugging your code, and so on.

Personally, I always use CAR and CDR, and have seen very little code
from other people that uses FIRST and REST, but maybe I'm just an
"old-timer" and mostly read code written by other old-timers.
I don't have any strong opinion about it, but am not bothered by calling
them CAR and CDR.  I never ever think about the contents of the address
register on an old IBM computer I never saw - my brain just has a picture
of boxes labeled CAR and CDR in a primitive abstract data type.  
Some people have been trying to get folks to switch to FIRST and REST
for at least the past 21 years, and mostly folks have not felt that it
was compelling enough to bother switching.

I don't love the names FIRST and REST, though.  They sound too general
to me, like they should be sequence functions, whereas CAR and CDR
always imply we're talking only about a cons cell.

P.S.
Too bad KMP isn't around: I'd like to hear his opinion on it!
From: Patrick O'Donnell
Subject: Re: 'first and rest' or 'car and cdr'
Date: 
Message-ID: <rtg053fuvb.fsf@ascent.com>
Christopher Stacy <······@spacy.Boston.MA.US> writes:

> >>>>> On 17 Jan 2002 19:26:09 -0500, Jeremy Whetzel ("Jeremy") writes:
>  Jeremy> I'm new to lisp and very interested in learning CL.  This may
>  Jeremy> be a nitpick sort of question, but I was reading in "Lisp 3rd
>  Jeremy> Edition" by Watson and Horn, and I noticed that it says that
>  Jeremy> using 'car' and 'cdr' are no longer commonly used, and have
>  Jeremy> been, for the most part, replaced with 'first' and 'rest'.
> 
> Yes, they suggest that "Some old-timers use CAR and CDR".
...
> Or today, for that matter. I think most people still call CAR and CDR.
...
> Personally, I always use CAR and CDR, and have seen very little code
> from other people that uses FIRST and REST, but maybe I'm just an
> "old-timer" and mostly read code written by other old-timers.

Speaking as another old-timer, I try _never_ to use CAR and CDR except
in expansions of macros that name what I'm really trying to do.  I've
had to maintain too much code with vipers nests of C*Rs that took far
longer than it should have to reconstruct what the author was trying
to accomplish.  The same goes for SECOND, THIRD, and so on.  Then,
again, I don't use FIRST and REST all that much, either.

> If you prefer to use FIRST and REST in your code, more power to you.
> You will still have to read code written by other people that contains
> CAR and CDR, however, and you are liable to see CAR and CDR appearing 
> in stack backtraces when debugging your code, and so on.

This is true.

		- Pat
From: Christopher Stacy
Subject: Re: 'first and rest' or 'car and cdr'
Date: 
Message-ID: <uadvbl63x.fsf@swingandcircle.com>
>>>>> On 18 Jan 2002 12:10:16 -0500, Patrick O'Donnell ("Patrick") writes:
 Patrick> Speaking as another old-timer, I try _never_ to use CAR and CDR except
 Patrick> in expansions of macros that name what I'm really trying to do.  I've
 Patrick> had to maintain too much code with vipers nests of C*Rs that took far
 Patrick> longer than it should have to reconstruct what the author was trying
 Patrick> to accomplish.  The same goes for SECOND, THIRD, and so on.  Then,
 Patrick> again, I don't use FIRST and REST all that much, either.

You're point is not about the CDR vs. REST naming style argument,
but rather about using CAR/CDR "at all" - to access components of 
a complex data object, and I think everybody agrees with you.

Assuming that the data is best thought about as being a list,
using CAR/CDR or FIRST/REST is appropriate, but more than two
levels deep is tricky, and more than three is just too many.
For example, CADR is okay, and the longest one I would ever 
write is CADAR.  It doesn't matter how you spell CADAR.
It is is equally as difficult as (CAR (CDR (CAR FOO))),
and  also  as  hard  to  grok as (FIRST (REST (FIRST FOO))).

The orthogonal point here being: don't use nested lists to represent 
the complex structure of individual objects.  That's the problem that
DEFSTRUCT was invented to solve!  (Or, if you must otherwise control 
the implementation of the representation, you can do it yourself by
writing your own structure macros or functional accessors.)

Lisp moved past this particular problem decades ago, but of
course there are probably people out there who haven't kept up.
From: Christopher Browne
Subject: Re: 'first and rest' or 'car and cdr'
Date: 
Message-ID: <a287e1$v988b$1@ID-125932.news.dfncis.de>
Jeremy Whetzel <·····@toadmail.com> writes:
> I'm new to lisp and very interested in learning CL.  This may be a
> nitpick sort of question, but I was reading in "Lisp 3rd Edition" by
> Watson and Horn, and I noticed that it says that using 'car' and
> 'cdr' are no longer commonly used, and have been, for the most part,
> replaced with 'first' and 'rest'.  I haven't been around on the list
> long, but in most tutorials and examples, I thought I saw car and
> cdr used more often.  Is there any difference in using one or the
> other, or is it mainly just a question of style?

It's not unlike the parentheses; once you get used to seeing them, you
don't really see them anymore.  The "old-timers" are so used to the
old way that they may not even _see_ that there's anything special
there to worry about.
-- 
(reverse (concatenate 'string ········@" "enworbbc"))
http://www3.sympatico.ca/cbbrowne/linux.html
"Parentheses?  What  parentheses? I  haven't  noticed any  parentheses
since my  first month of Lisp  programming.  I like to  ask people who
complain about  parentheses in  Lisp if they  are bothered by  all the
spaces between words in a newspaper..."
-- Kenny Tilton <····@liii.com>