Jump to content

I'M REALLY PUZZLED FOR COMPARING


hosyn

Recommended Posts

I'M REALLY PUZZLED FOR COMPARING 2 LIST WE HAVE

(setq list1 '(B A H Y U T F))     
(setq list2 '(B K S F R W T O P H N))
(vl-remove-if-not '(lambda (i) (member i list1)) list2)
I KNOW THAT  FOLOWING IS FOR COMPARE TO SIMPLE LIST1 AND LIST2 AND GIVE US:
             '(B F T)

NOW I WANT
(setq list1 '(B A H Y U T F))     
(setq list2 '((B 8) (A 3) (M 3) (N 2) (F 3))
I WANT COMPARE 2 LIST ON CHECK CAR OF EACH THEM AND GETTING RESULT
              (B 8) (A 3) (F 3)

I APPRECIATE FOR ANY HELPING IN ADVANCE 

Link to comment
Share on other sites

thank you so much for reply , when i look closer figure out that must modified somehow for  :

desire-block-names ("ss" "sa" "sk" "sp" "sh"))     
block-list         (("ss" . 1) ("sw" . 1) ("sa" . 1) ("sp" . 1) ("sk" . 1) ("sq" . 1) ("sx" . 1) ("sh" . 1))

result-->>         (("ss" . 1) ("sa" . 1) ("sk" . 1) ("sh" . 1))

how we can modified folowing

(vl-remove-if-not '(lambda (i) (member (car i) list1)) list2)
Edited by hosyn
Link to comment
Share on other sites

Thank you marko

OK, I see, unforchanetly I pulled my tooth and I feel awfully ache, I couldn't concentrate 

Edited by hosyn
Link to comment
Share on other sites

AND may i ask how we can modified for

desire-block-names ((rgt "oldss" "ss") (rgt "oldsa" "sa") (rgt "oldsk" "sk") (rgt "oldsp" "sp") (rgt "oldsh" "sh"))     
block-list         (("ss" . 1) ("sw" . 1) ("sa" . 1) ("sp" . 1) ("sk" . 1) ("sq" . 1) ("sx" . 1) ("sh" . 1))

result-->>         (("ss" . 1) ("sa" . 1) ("sk" . 1) ("sh" . 1))

 

Link to comment
Share on other sites

3 hours ago, hosyn said:

AND may i ask how we can modified for


desire-block-names ((rgt "oldss" "ss") (rgt "oldsa" "sa") (rgt "oldsk" "sk") (rgt "oldsp" "sp") (rgt "oldsh" "sh"))     
block-list         (("ss" . 1) ("sw" . 1) ("sa" . 1) ("sp" . 1) ("sk" . 1) ("sq" . 1) ("sx" . 1) ("sh" . 1))

result-->>         (("ss" . 1) ("sa" . 1) ("sk" . 1) ("sh" . 1))

 

 

If desired-block-names  '((rgt "oldss" "ss") (rgt "oldsa" "sa") (rgt "oldsk" "sk") (rgt "oldsp" "sp") (rgt "oldsh" "sh")) is a just a list; notice the quote mark before the list. then

 

(vl-remove-if-not '(lambda (i) (member (car i) (mapcar 'caddr desire-block-names))) block-list)

And the return is => (("ss" . 1) ("sa" . 1) ("sp" . 1) ("sk" . 1) ("sh" . 1))

You missed ("sp" . 1) from your result list

 

If (rgt "oldss" "ss")... is a function and the list should be (list (rgt "oldss" "ss") (rgt "oldsa" "sa") (rgt "oldsk" "sk") (rgt "oldsp" "sp") (rgt "oldsh" "sh"))), it would depend on what the function returns. If the return is a single text item then

 

(vl-remove-if-not '(lambda (i) (member (car i) desire-block-names)) block-list)

 

as the resultant list would be in the same format as in post 3

 

 

Edited by dlanorh
clarity
Link to comment
Share on other sites

10 hours ago, dlanorh said:

If (rgt "oldss" "ss")... is a function and the list should be (list (rgt "oldss" "ss") (rgt "oldsa" "sa") (rgt "oldsk" "sk") (rgt "oldsp" "sp") (rgt "oldsh" "sh"))), it would depend on what the function returns. If the return is a single text item then...

 

Use this regardless of the result of the fucntion rgt is a list or a single string..

(vl-remove-if-not '(lambda (i) (member (car i) (apply 'append desire-block-names))) block-list))

 

Edited by pBe
  • Like 1
Link to comment
Share on other sites

THERES  NO WORD TO THANK YOU ENOUGH YOU ALL HELPER GUYS IN THE CADTUTOR. 💚💚💚💚

THANK YOU SO MUCH...........................

Link to comment
Share on other sites

RGT INDEED ABBRATIVE, AND JUST FOR CLEARING OF MY EXAMPLE IN MY CODE LISP, ITS POINTED TO RENAME FUNCTION OF MYBLOCK . 

YESTERDAY I HAD TO PULL MY TOOTH FOR FIRST TIME AND DESPITE THE AWFULLY PAIN I LIKED TO HANG OUT IN THE AMAZING LISTS OF AUTOLISP LANGUAGE😍

 

Link to comment
Share on other sites

BY THE WAY I FALL IN LOVE WITH THIS FUNCTION    

(vl-remove-if-not

AND LAST NIGHT STUDIED A LONG TIME  ABOUT IT , ARE THERE PROPER WAY TO COMPREHENSIVE MORE THAN .?

Link to comment
Share on other sites

Hi again dear Coders

I try to modify above code for getting the following result and not succeed :

block-list   (("A-old" . 1) ("B-old" . 1) ("C-old" . 1) ("D-old" . 1) ("E-old" . 1) ("F-old" . 1) ("G-old" . 1) ("H-old" . 1))
compare list ((rgt "A-old" "A-new") (rgt "C-old" "C-new") (rgt "K-old" "K-new") (rgt "E-old" "E-new") (rgt "D-old" "D-new")  (rgt "H-old" "H-new"))     


result-->>   (("A-new" . 1) ("C-new" . 1) ("E-new" . 1) ("H-new" . 1))

Any helping will be appreciated.🙄

Link to comment
Share on other sites

If RGT is a function, then maybe you'd want to let us know what (rgt "A-old" "A-New") would evaluate to?

 

Or show us what the function rgt does?

  • Thanks 1
Link to comment
Share on other sites

7 minutes ago, Jonathan Handojo said:

If RGT is a function, then maybe you'd want to let us know what (rgt "A-old" "A-New") would evaluate to?

 

Or show us what the function rgt does?

RGT is not a function, is  just vanilla variable or can be simple text like that "hfgdh".

Link to comment
Share on other sites

(defun ts ( / l1 l2)

    ;; Your lists
    (setq l1 '(("A-old" . 1) ("B-old" . 1) ("C-old" . 1) ("D-old" . 1) ("E-old" . 1) ("F-old" . 1) ("G-old" . 1) ("H-old" . 1)))
    (setq l2 '((rgt "A-old" "A-new") (rgt "C-old" "C-new") (rgt "K-old" "K-new") (rgt "E-old" "E-new") (rgt "D-old" "D-new")  (rgt "H-old" "H-new")))

    ;; Routine

    (vl-remove nil
	(mapcar
	    '(lambda (x / asc)
		 (if (setq asc (assoc (cadr x) l1))
		     (cons (caddr x) (cdr asc))
		     )
		 )
	    l2
	    )
	)
    )

 

  • Like 1
Link to comment
Share on other sites

9 hours ago, hosyn said:

Hi again dear Coders

I try to modify above code for getting the following result and not succeed :


block-list   (("A-old" . 1) ("B-old" . 1) ("C-old" . 1) ("D-old" . 1) ("E-old" . 1) ("F-old" . 1) ("G-old" . 1) ("H-old" . 1))
compare list ((rgt "A-old" "A-new") (rgt "C-old" "C-new") (rgt "K-old" "K-new") (rgt "E-old" "E-new") (rgt "D-old" "D-new")  (rgt "H-old" "H-new"))     


result-->>   (("A-new" . 1) ("C-new" . 1) ("E-new" . 1) ("H-new" . 1))

Any helping will be appreciated.🙄

 

Why is "D-new" not included in the result?

  • Thanks 1
Link to comment
Share on other sites

22 minutes ago, Lee Mac said:

 

Why is "D-new" not included in the result?

 

7 hours ago, Jonathan Handojo said:

(defun ts ( / l1 l2)

    ;; Your lists
    (setq l1 '(("A-old" . 1) ("B-old" . 1) ("C-old" . 1) ("D-old" . 1) ("E-old" . 1) ("F-old" . 1) ("G-old" . 1) ("H-old" . 1)))
    (setq l2 '((rgt "A-old" "A-new") (rgt "C-old" "C-new") (rgt "K-old" "K-new") (rgt "E-old" "E-new") (rgt "D-old" "D-new")  (rgt "H-old" "H-new")))

    ;; Routine

    (vl-remove nil
	(mapcar
	    '(lambda (x / asc)
		 (if (setq asc (assoc (cadr x) l1))
		     (cons (caddr x) (cdr asc))
		     )
		 )
	    l2
	    )
	)
    )

 

Dear mate

I cheked the code but dont filter by compare list?!!!!!

Link to comment
Share on other sites

I'm not quite sure what you mean though. The function I wrote above should return the desired result

  • Like 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...