Jump to content

make list


Mirsh

Recommended Posts

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" ) )

Β 

Β 

Link to comment
Share on other sites

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 by Lee Mac
  • Thanks 1
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...