hosyn Posted July 18, 2020 Posted July 18, 2020 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 Quote
pBe Posted July 18, 2020 Posted July 18, 2020 (vl-remove-if-not '(lambda (i) (member (car i) list1)) list2) 1 Quote
hosyn Posted July 18, 2020 Author Posted July 18, 2020 (edited) 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 July 18, 2020 by hosyn Quote
marko_ribar Posted July 18, 2020 Posted July 18, 2020 Use the same code... You forgot : ("sp" . 1) in result... ; ) 1 Quote
hosyn Posted July 18, 2020 Author Posted July 18, 2020 (edited) Thank you marko OK, I see, unforchanetly I pulled my tooth and I feel awfully ache, I couldn't concentrate Edited July 18, 2020 by hosyn Quote
hosyn Posted July 18, 2020 Author Posted July 18, 2020 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)) Quote
dlanorh Posted July 18, 2020 Posted July 18, 2020 (edited) 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 July 19, 2020 by dlanorh clarity Quote
pBe Posted July 19, 2020 Posted July 19, 2020 (edited) 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 July 19, 2020 by pBe 1 Quote
hosyn Posted July 19, 2020 Author Posted July 19, 2020 THERES NO WORD TO THANK YOU ENOUGH YOU ALL HELPER GUYS IN THE CADTUTOR. THANK YOU SO MUCH........................... Quote
pBe Posted July 19, 2020 Posted July 19, 2020 (edited) Glad we could help. Tell us, what is rgt shown on your list? Edited July 19, 2020 by pBe 1 Quote
hosyn Posted July 19, 2020 Author Posted July 19, 2020 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 Quote
hosyn Posted July 19, 2020 Author Posted July 19, 2020 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 .? Quote
hosyn Posted July 26, 2020 Author Posted July 26, 2020 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. Quote
Jonathan Handojo Posted July 26, 2020 Posted July 26, 2020 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? 1 Quote
hosyn Posted July 26, 2020 Author Posted July 26, 2020 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". Quote
Jonathan Handojo Posted July 26, 2020 Posted July 26, 2020 (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 ) ) ) 1 Quote
Lee Mac Posted July 26, 2020 Posted July 26, 2020 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? 1 Quote
hosyn Posted July 26, 2020 Author Posted July 26, 2020 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?!!!!! Quote
Jonathan Handojo Posted July 26, 2020 Posted July 26, 2020 I'm not quite sure what you mean though. The function I wrote above should return the desired result 1 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.