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

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

beginnerquestion (nconc)


From: Stefan Huchler
Subject: beginnerquestion (nconc)
Date: Fri, 17 Mar 2017 06:58:17 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux)

Hello,

I am a bit anoyed by push and reverse lists its not very straightforward
solution to create lists in loops, I found in the doku the nconc macro,
which looks like some sort of push that puts sequences at the end
instead of the beginning.

So I tried to use it instead of push but it behaves strange, it only
works with nonempty lists:

Code to replace:

(setq test '())
(push '(a) test)
(push '(b) test)
(print (reverse test))

What I would expect to work:

(setq test2 '())
(nconc test2 '((a)))
(nconc test2 '((b)))
(print test2)

But only if I setq test2 the value of the first nconc expression it
works. Which is ok for that example but does not work very well in a
loop.

Is there a trick or another expression/macro that does what I want?

I guess there is add-to-list but it removes equal elements what I dont
want.

Thank you.




reply via email to

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