Using AutoLISP, I have the following list set to a variable "dwginfo" (the list was generated using the DOSLib function "dos_getfilem"):
("C:\\Drawing\\Temp\\000aaTest\\DwgConvert\\" "test1.dwg" "test1x.dwg" "test2.dwg" "test2x.dwg" "test3.dwg" "test4.dwg")
I take the first element and store it as "path":
Command: (setq path (car dwginfo))
"C:\\Drawing\\Temp\\000aaTest\\"
Then I remove the first element and store this new list as "names":
Command: (setq names (cdr dwginfo))
("test1.dwg" "test1x.dwg" "test2.dwg" "test2x.dwg" "test3.dwg" "test4.dwg")
Now, what I would like to do is create a new list consisting of each element in "names" with the path added to it (in front).
I have tried this with varying combinations of list and foreach, but the closest I can get is this:
Command: (setq dwgs (list (foreach nam names (strcat path nam))))
("C:\\Drawing\\Temp\\000aaTest\\test4.dwg")
Foreach only returns the results of the last concatenation, so that's all I get in the "list".
How can I build a list containing all of the concatenated names?
Thanks.
Solved! Go to Solution.
Solved by hmsilva. Go to Solution.
hmsilva's way is certainly more concise, but here's a way to re-arrange mostly the elements of yours to do it:
(foreach nam names (setq dwgs (cons (strcat path nam) dwgs)))
If the order needs to be the same as in the names list, you would then want to:
(setq dwgs (reverse dwgs))
I had a feeling it would involve mapcar, but couldn't figure out how to use it. And lambda has always been a mystery for me.
Thank you very much for that, Henrique. It is exactly what I needed.
I should've thought of cons.
Thanks, Kent. It's always nice to have alternatives (even less concise ones).
@dmfrazier wrote:
I had a feeling it would involve mapcar, but couldn't figure out how to use it. And lambda has always been a mystery for me.
Thank you very much for that, Henrique. It is exactly what I needed.
You're welcome, dmfrazier
Glad I could help.
May be helpful this Lee Mac's explanation Mapcar & Lambda
Henrique
@dmfrazier wrote:And lambda has always been a mystery for me.
There are differences but essentially, for most practical purposes, Lambda is the same as defun without the need for a name.
defun = named function
lambda = nameless function