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

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

Re: Appending lists


From: Emanuel Berg
Subject: Re: Appending lists
Date: Tue, 15 Jun 2021 10:27:48 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> Also check out `nconc'
>
> (nconc '(1 2 3) '(4 5) '(6)) ; (1 2 3 4 5 6) - if this works for you, use it
> (nconc '(1 2 3) '(4 5)   6 ) ; (1 2 3 4 5 . 6) - see, last "list" isn't a 
> list!
>
> There was a trick with nconc, you could reverse a list in
> constant time, right? I think that was it but that's all
> I remember.

Probably that wasn't `nconc' but `nreverse', I think!

  (nreverse '(flip six three hole)) ; (hole three six flip)

Yeah, and it didn't take very long either...

Here it says

  Don't use nreverse on quoted list literals; it is undefined
  behavior and may behave in surprising ways, since it is
  de facto self-modifying code. [1]

Hm ... quoted list literals? Is this better?

  (nreverse (list 'flip 'six 'three 'hole)) ; (hole three six flip)

Whats the difference and how does self-modifying code come in?
I did that once but don't remember how it worked. Is that
a function that modifies its own definition when executed?
Funky ... but does that happen here? Where?

But as for reversing the list it seems to "de facto" work
anyway :)

[1] https://stackoverflow.com/a/34423234

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

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