unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* beginnerquestion (nconc)
@ 2017-03-17  5:58 Stefan Huchler
  2017-03-17  7:33 ` Thien-Thi Nguyen
  2017-03-17 14:42 ` Yuri Khan
  0 siblings, 2 replies; 17+ messages in thread
From: Stefan Huchler @ 2017-03-17  5:58 UTC (permalink / raw)
  To: help-gnu-emacs

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.




^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2017-03-22 19:00 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-17  5:58 beginnerquestion (nconc) Stefan Huchler
2017-03-17  7:33 ` Thien-Thi Nguyen
2017-03-17  8:52   ` Thien-Thi Nguyen
2017-03-17 14:19   ` Stefan Huchler
2017-03-17 14:48     ` tomas
2017-03-17 14:42 ` Yuri Khan
2017-03-17 16:59   ` Stefan Huchler
2017-03-17 17:20     ` Drew Adams
2017-03-17 17:32       ` Drew Adams
2017-03-18  2:15     ` Stefan Monnier
2017-03-21 16:47       ` Stefan Huchler
2017-03-21 16:59       ` Stefan Huchler
2017-03-21 20:14         ` John Mastro
2017-03-22  0:32           ` Stefan Huchler
2017-03-22 15:02             ` Michael Heerdegen
2017-03-22 19:00             ` John Mastro
2017-03-21 11:05     ` Michael Heerdegen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).