help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Chopping the last element of a list


From: Drew Adams
Subject: Re: Chopping the last element of a list
Date: Fri, 29 Apr 2022 01:02:50 +0000

> Right, so you see the problem with functions like `last` and `butlast`
> which work on the end of a list: they are only useful if that's the
> only thing you do with that list.  As soon as you try to do more, then
> you end up traversing the list multiple times.
> 
> > Shouldn't emacs provide a function which does it in one step, so the
> > list isn't walked twice? E.g. (choplast mylist)
> 
> That would just suffer from the same problem you just experienced
> (i.e. everytime you need to do `choplast` plus something else, you'll
> end up traversing the list twice).
> 
> Instead, every time you need to work on the end of a list, you should
> start by getting a reference to that end (presumably with `last` with
> an appropriate N) and then you work locally on that end.

+1.  Well put.

<<attachment: winmail.dat>>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]