From: Lawrence Troxler
Subject: #'first and #'last inconsistency
Date: 
Message-ID: <66aeot$j1i$1@mycroft.westnet.com>
It looks like I've come across another un-intuitive aspect of the CL
language: The functions first, second, third, and nth, all return the
first,
second, or nth car of their argument.

Obviously, then, "last" would clearly return the car of the last cons cell
of its argument, right? Guess again. It actually returns the last cons
cell itself, so that "last" is actually a single-element list!

Anyhow, I'd be curious to hear of the history behind this one!

Larry



-- 
--  Larry Troxler  --  ··@westnet.com  --  Patterson, NY USA  --
  

From: Barry Margolin
Subject: Re: #'first and #'last inconsistency
Date: 
Message-ID: <66ajcb$2tn@pasilla.bbnplanet.com>
In article <············@mycroft.westnet.com>,
Lawrence Troxler  <··@westnet.com> wrote:
>Obviously, then, "last" would clearly return the car of the last cons cell
>of its argument, right? Guess again. It actually returns the last cons
>cell itself, so that "last" is actually a single-element list!
>
>Anyhow, I'd be curious to hear of the history behind this one!

The main expected use of LAST is to allow you to RPLACD the cons cell in
order to extend the list.

As for the reason for the inconsistent naming, it's historical.  MacLisp
didn't have FIRST, SECOND, etc., but it did have LAST.  Common Lisp
inherited this function, keeping its name.  But FIRST through FOURTH were
also added (I think they came from NIL and/or Zetalisp), with their
untuitive meanings.

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Cambridge, MA
Support the anti-spam movement; see <http://www.cauce.org/>
Please don't send technical questions directly to me, post them to newsgroups.
From: Kent M Pitman
Subject: Re: #'first and #'last inconsistency
Date: 
Message-ID: <sfwd8jb0zgl.fsf@world.std.com>
Barry Margolin <······@bbnplanet.com> writes:

> In article <············@mycroft.westnet.com>,
> Lawrence Troxler  <··@westnet.com> wrote:
> >Obviously, then, "last" would clearly return the car of the last cons cell
> >of its argument, right? Guess again. It actually returns the last cons
> >cell itself, so that "last" is actually a single-element list!
> >
> >Anyhow, I'd be curious to hear of the history behind this one!
> 
> The main expected use of LAST is to allow you to RPLACD the cons cell in
> order to extend the list.
> 
> As for the reason for the inconsistent naming, it's historical.  MacLisp
> didn't have FIRST, SECOND, etc., but it did have LAST.  Common Lisp
> inherited this function, keeping its name.  But FIRST through FOURTH were
> also added (I think they came from NIL and/or Zetalisp), with their
> untuitive meanings.

It's also for just this reason that I asked X3J13 to add a second arg
to LAST, so that it would be more intuitive...  and they did.  It now
returns the last N, by default the last 1, but since it can return a
variable number it has to always return the result as a list (well, at
least a CONS).  Kind of a kludge, I guess.  But BARMAR's right, the
real place where LAST is used is when you want to hold the last cell
for later RPLACD.
From: William Paul Vrotney
Subject: Re: #'first and #'last inconsistency
Date: 
Message-ID: <vrotneyEKr2CA.FAG@netcom.com>
In article <············@mycroft.westnet.com> Lawrence Troxler
<··@westnet.com> writes:

> 
> It looks like I've come across another un-intuitive aspect of the CL
> language: The functions first, second, third, and nth, all return the
> first,
> second, or nth car of their argument.
> 
> Obviously, then, "last" would clearly return the car of the last cons cell
> of its argument, right? Guess again. It actually returns the last cons
> cell itself, so that "last" is actually a single-element list!
> 
> Anyhow, I'd be curious to hear of the history behind this one!
> 
> Larry
> 

Intuitiveness is in the mind of the beholder.

If LAST were not defined this way then we would need two functions: LASTCDR
which would give you what LAST now gives you and another to given you the
last CAR.  Also LAST is more symmetrical to BUTLAST and NBUTLAST.
Also LAST will work if the list is dotted, for example

        (last '(a b c . d)) => (C . D)

Much as we get used to the idiom

        (cdr (assoc key list))

we get used to the idom

        (car (last list))

If it really bugs you, you can always do something like

        (defun final (list) (car (last list)))

-- 

William P. Vrotney - ·······@netcom.com