Mirsh Posted December 29, 2020 Posted December 29, 2020 Hi Dears, I appreciate if you help me for making a list ; In a list contain several cons that It's cons have several with same CAR ; can i merge CDR of these cons together and a " & " between them , like this ( ( 1 . "a" ) ( 23 . "b" ) ( 42 . "c" ) ( 1 . "d" ) ( 23 . "e" ) ( 42 . "f" ) (42 . "g" ) ) ====> CONVERT TO====> ( ( 1 "a" " & " "d" ) ( 23 "b" " & " "e" ) ( 42 "c" " & " "f" " & " "g" ) ) Quote
Lee Mac Posted December 29, 2020 Posted December 29, 2020 (edited) This type of operation arises quite frequently - here's one way to approach it: (defun f ( l / a r ) (foreach x (reverse l) (if (setq a (assoc (car x) r)) (setq r (subst (vl-list* (car x) (cdr x) " & " (cdr a)) a r)) (setq r (cons (list (car x) (cdr x)) r)) ) ) r ) _$ (f '((1 . "a")(23 . "b")(42 . "c")(1 . "d")(23 . "e")(42 . "f")(42 . "g"))) ((1 "a" " & " "d") (23 "b" " & " "e") (42 "c" " & " "f" " & " "g")) Edited December 29, 2020 by Lee Mac 1 Quote
Mirsh Posted December 29, 2020 Author Posted December 29, 2020 autoLEEsp's GOAT; thanks aloooot happy to have a reply from you thanks it works Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.