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 17:24:46 -0500
User-agent: Gnus/5.13 (Gnus v5.13)

>> > That's because adding to the end of a Lisp list is
>> > a bad idea.
> The bad idea comment disregards necessity.

Another way to look at it is that you disregard the possibility to
change your necessity.

> Suppose I am accumulating indicators that are done at increasing value
> of time and want to introduce them into another list in the order they
> were encountered.  What should one  handle these things?

Add them in the reverse order and finish with a simple `reverse`.
That's a very standard design pattern with singly-linked lists (and in
many/most cases the final `reverse` can be an `nreverse`).
Of course, in practice I'm sure there are many other options if you
consider the problem in context where you can make changes to other
parts of your code (e.g. to use something else than a list).


        Stefan




reply via email to

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