[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [External] : Re: Chopping the last element of a list
From: |
address@hidden |
Subject: |
Re: [External] : Re: Chopping the last element of a list |
Date: |
Sat, 30 Apr 2022 07:25:57 +0200 |
On Fri, Apr 29, 2022 at 03:55:39PM +0000, Drew Adams wrote:
> > > > Here. It returns the last element, and it
> > > > chops that last element off the list.
> > >
> > > Thanks. It's quite simple and useful to have along with
> > > last/butlast/etc.
> > >
> > > Will you put it into subr.el, so emacs has it built-in ?
> >
> > Read Drew's code again. Read the examples he provided.
> >
> > Now, answer this one question: for a list with exactly
> > one element, say
> >
> > (setq foo '(1))
> >
> > what is its last element? What would you expect choplast
> > to do? What does Drew's implementation do? Surprise?
>
> Yes. If you want to return 1 in that case then
> be aware that there's no way to modify a cons
> to turn it into nil. (nil is a scalar - what
> Lisp calls an "atom"; a cons is not.)
I know...
> I intentionally kept the same behavior as `butlast':
> return nil and don't change anything for a list
> with less than 2 elements.
...and I know you know :)
I wanted to help OP to understand why changing things "in
place" has this special feel about it in Lisp land :-)
Cheers
--
t
signature.asc
Description: PGP signature
Re: Chopping the last element of a list, Drew Adams, 2022/04/28