Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appending lists with symbol names specified in a list of strings

Tags:

emacs

lisp

elisp

This probably is easy but I cant seem to get

lets say I have a b and d

(setq a '(x y))
(setq b '(p q))
(setq d '("a" "b"))

how can get a list containing (x y p q) with the information I have with d

UPDATE; Ok what I had tried was this

(apply 'nconc (mapcar (lambda (x)
               (symbol-value (intern x)))
           d))

but I dont really understand what nconc does. if evaluate twice, value changes. thrice emacs goes without response

like image 832
kindahero Avatar asked Nov 26 '25 15:11

kindahero


1 Answers

This should do it:

(apply 'append (mapcar (lambda (name) (symbol-value (intern name))) d))

Can you change what d to use symbols instead of strings? It would be much simpler to do:

(setq d '(a b))
(apply 'append (mapcar 'symbol-value d))

If the contents of a and b are known at the time you set d, you could even do this:

(setq d `(,@a ,@b))
like image 123
Michael Hoffman Avatar answered Nov 29 '25 17:11

Michael Hoffman