I have a list -
(setq List1 (list "Line A" "Line B" "Line C"))
I would like to add each item in an existing list to a new list -
(setq ListNew (list "This is some text" "This is more text"
;the following is the part I can't figure out - it just adds the list to the list, not the individual items
(mapcar '(lambda (x) x) List1)
))
I am looking for ListNew to be - (a list with 5 strings)
"This is some text"
"This is more text"
"Line A"
"Line B"
"Line C"
(setq List1 (list "Line A" "Line B" "Line C")) (append (list "additional 1" "additional 2") List1) OR (cons "additional 1" (cons "additional 2" List1))
This gives you two options. append is easier in this regard, but will be much slower than cons. If you know what they items will be (set number of), then I'd go with cons.
I understand how to use the append and cons.
I was hoping I could add the values during the setq function itself.
@Anonymous wrote:I understand how to use the append and cons.
I was hoping I could add the values during the setq function itself.
I'm not sure I understand. It can be done at any time. If you know the values at the time of originally construction the list, just append/cons as shown or construct the list just including the new items.
@mid-awe wrote:
Thank you for the answer. Right now I use ssadd, but I have to know how many selection sets are going to be merged, so I'll dig into your solution. Again thank you.
No problem.
This should give you something to play with. I elected to create a new, rather than adding to one of the unknown number of picksets, so this would change the actual pickset. This will handle a list of as many picksets (selection sets) as you can throw at it and combine each ename into one pickset.
(defun _ssUnion (ssList / add i) (setq add (ssadd)) (foreach ss ssList (if (eq (type ss) 'PICKSET) (repeat (setq i (sslength ss)) (ssadd (ssname ss (setq i (1- i))) add)) ) ) (if (> (sslength add) 0) add ) )