lists inside list issue

lists inside list issue

DGRL
Advisor Advisor
842 Views
2 Replies
Message 1 of 3

lists inside list issue

DGRL
Advisor
Advisor

 

 

 

fixed it already

 

 

 

 

 

 

 

 

Dear coders,

 

Have a question about mapcar.

Probably im doing it wrong

 

I read multiple cells from xls to make a list containg 7 others lists

Looks like this

 

(("OLD ATT" "ISO_PIPESPEC" "ISO_MEDIUM" "ISO_DESIGN_PRESS" ) ("NEW ATT" "n.v.t.1" "n.v.t.2" "n.v.t.3") ("PROMPT" "Prompt 1" "Prompt 2" "Prompt 3") ("ISO-QAZ" "val aa01" "val aa02" "val aa03") ("ISO-QQ" "val a1" "val a2" "val a3") ("ISO-QA" "val b1" "val b2" "val b3") ("ISO-AZ" "val c1" "val c2" "val c3"))


with

(setq b (mapcar 'car a))

Im making a list containing all the first elements

("OLD ATT" "NEW ATT" "PROMPT" "ISO-QAZ" "ISO-QQ" "ISO-QA" "ISO-AZ")

 

With
(setq c (mapcar 'cdr a))

Im making a list containing the other 7 lists without the first element in it

 

(("ISO_PIPESPEC" "ISO_MEDIUM" "ISO_DESIGN_PRESS" "ISO_DESIGN_TEMP") ("n.v.t.1" "n.v.t.2" "n.v.t.3" "n.v.t.4") ("Prompt 1" "Prompt 2" "Prompt 3" "Prompt 4") ("val aa01" "val aa02" "val aa03" "val aa04") ("val b1" "val b2" "val b3" "val b4") ("val c1" "val c2" "val c3" "val c4"))

Now I need to combine this lists again
Using
(setq d (mapcar 'list (cdr c) (cdr b)))
This will create the list I need only IT IS MISSING the whole first list i.e (OLD_ATT)
So the list looks like this
(("NEW ATT" ("Prompt 1" "Prompt 2" "Prompt 3" "Prompt 4")) ("PROMPT" ("val aa01" "val aa02" "val aa03" "val aa04")) ("ISO-QAZ" ("val a1" "val a2" "val a3" "val a4")) ("ISO-QQ" ("val b1" "val b2" "val b3" "val b4")) ("ISO-QA" ("val c1" "val c2" "val c3" "val c4")))

 

 

Changing cdr into car results in a error

(setq d (mapcar 'list (car c) (car b)))

error: bad argument type: consp "OLD ATT"

 



What function do I need to use to get a list containing all the lists?

Kind regards

 

 

 

 

 

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Accepted solutions (1)
843 Views
2 Replies
Replies (2)
Message 2 of 3

_gile
Consultant
Consultant
Accepted solution

Hi,

 

I'm not sure to understand what you want to achieve, but

 

(mapcar 'cons b c)

will return the original list (a):

 

(("OLD ATT" "ISO_PIPESPEC" "ISO_MEDIUM" "ISO_DESIGN_PRESS")
  ("NEW ATT" "n.v.t.1" "n.v.t.2" "n.v.t.3")
  ("PROMPT" "Prompt 1" "Prompt 2" "Prompt 3")
  ("ISO-QAZ" "val aa01" "val aa02" "val aa03")
  ("ISO-QQ" "val a1" "val a2" "val a3")
  ("ISO-QA" "val b1" "val b2" "val b3")
  ("ISO-AZ" "val c1" "val c2" "val c3")
)

 

Take care that

 

(mapcar 'list b c)

does not return the same list:

 

(("OLD ATT" ("ISO_PIPESPEC" "ISO_MEDIUM" "ISO_DESIGN_PRESS"))
  ("NEW ATT" ("n.v.t.1" "n.v.t.2" "n.v.t.3"))
  ("PROMPT" ("Prompt 1" "Prompt 2" "Prompt 3"))
  ("ISO-QAZ" ("val aa01" "val aa02" "val aa03"))
  ("ISO-QQ" ("val a1" "val a2" "val a3"))
  ("ISO-QA" ("val b1" "val b2" "val b3"))
  ("ISO-AZ" ("val c1" "val c2" "val c3"))
)



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 3

DGRL
Advisor
Advisor

Dear @_gile

 

 

This one did the trick

(mapcar 'list c b)

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes