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

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

Re: Easy to add with push but not to the end of a list


From: Stefan Monnier
Subject: Re: Easy to add with push but not to the end of a list
Date: Mon, 28 Nov 2022 00:18:08 -0500
User-agent: Gnus/5.13 (Gnus v5.13)

> Although it is easy to add to a list using push, it currently looks
> hideous to be able to  add to the end of a list.

That's because adding to the end of a Lisp list is a *bad* idea.

Your better option usually is to avoid doing that by keeping your list
in reverse order while you add elements to it and to reverse it at the end.

> Would be appreciated if Emacs could have a function as simple
> to add to the end of a list?

    (cl-callf PLACE (lambda (xs) (append xs (list VAL))))

while `push` is constant time, the above has O(N) complexity.


        Stefan




reply via email to

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