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

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

Chopping the last element of a list


From: emacsq
Subject: Chopping the last element of a list
Date: Thu, 28 Apr 2022 09:21:23 +0000

If I want to do this then I can do, for example:

(prog1
(car (last mylist)) (setq mylist (nbutlast mylist)))

But here last and nbutlast walks the list twice unnecessarily.

Shouldn't emacs provide a function which does it in one step, so the list isn't 
walked twice?

E.g. (choplast mylist)

which returns a cons cell of (LAST . CHOPPEDLIST)

Of course, returning two values is not very lispy, but at least it could be 
more efficient.

Is there an existing function which does this in one step? If not, shouldn't 
there be one built-in emacs, for efficient manipulation of the list's end?

reply via email to

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