Mirsh Posted December 29, 2020 Share 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 Link to comment Share on other sites More sharing options...
Lee Mac Posted December 29, 2020 Share 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 Link to comment Share on other sites More sharing options...
Mirsh Posted December 29, 2020 Author Share Posted December 29, 2020 autoLEEsp's GOAT; thanks aloooot happy to have a reply from you thanks it works Quote Link to comment Share on other sites More sharing options...
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.