Author Topic: list comparison  (Read 11029 times)

0 Members and 1 Guest are viewing this topic.

daron

  • Guest
list comparison
« on: July 07, 2005, 03:28:23 PM »
I have some lists
(1 11)
(5 11 45)
I want to compare these lists to return t or nil if either number in the first list is = to any number in the second list. I know this can be done, but I'm frying my brain trying to remember how. :evil: Please help. I've tried different variations of member, mapcar, and foreach, but all attempts have resulted nil when it's obvious that there is a match.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
list comparison
« Reply #1 on: July 07, 2005, 03:33:52 PM »
Consider --

Code: [Select]
(mapcar    
   '(lambda (x) (and (member x '(5 11 45))))
   '(1 11)
)

Now rewrite it as a function that takes two arguments.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

JohnK

  • Administrator
  • Seagull
  • Posts: 10637
list comparison
« Reply #2 on: July 07, 2005, 03:37:01 PM »
Wasnt this just mentioned? ...Yep! Heres my example from the post.  (I'll post my example code and then i'll go get the link for ya.)

Code: [Select]

(defun test (lst-c lst-m / inlist)
 
  (defun inlist (? lst)
    (and (member ? lst)) )
 
  (cond
    ((inlist (car lst-c) lst-m)
     (alert "Found a match")
     (test (cdr lst-c) lst-m))
    ( T (cond
          ((<= (length lst-c) 1)
           "End of list reached"
           )
          ( T (test (cdr lst-c) lst-m))))) )
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

daron

  • Guest
list comparison
« Reply #3 on: July 07, 2005, 03:37:02 PM »
which is exactly what I intend to do. Thank you. I'm still trying to get my mind around the various ways to use member, mapcar and lambda.

JohnK

  • Administrator
  • Seagull
  • Posts: 10637
list comparison
« Reply #4 on: July 07, 2005, 03:38:48 PM »
Holly cow. You guys move fast!

Well anyways, heres the link i promised.

EDIT: *sigh* (I forgot the link!??!)

http://www.theswamp.org/phpBB2/viewtopic.php?t=5656
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
list comparison
« Reply #5 on: July 07, 2005, 03:39:43 PM »
Quote from: daron
which is exactly what I intend to do. Thank you. I'm still trying to get my mind around the various ways to use member, mapcar and lambda.

My pleasure. Don't forget about the power in the apply, catch-all-apply, foreach etc. functions too.

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

daron

  • Guest
list comparison
« Reply #6 on: July 07, 2005, 03:43:46 PM »
Here's the answer to your request:
Code: [Select]
(defun comparison (grlist complist)
     (mapcar
 '(lambda (x) (and (member x complist)))
 grlist
     )
)


John, funny you posted that code. I was searching before posting, but I think my mind was so wrapped up in how I was failing, that I didn't think it would apply. Thanks to both of you.

daron

  • Guest
list comparison
« Reply #7 on: July 07, 2005, 03:45:26 PM »
MP, I'll have to look at the apply's, but I was also trying foreach with no luck. End of the day stress I think and lack of coding for months.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
list comparison
« Reply #8 on: July 07, 2005, 03:47:49 PM »
Here's one that uses foreach & member...
Code: [Select]

(defun inList? (l1 l2 / res)
  (foreach x l1
    (if (member x l2)
      (setq res t)
      )
    )
  res
  )

JohnK

  • Administrator
  • Seagull
  • Posts: 10637
list comparison
« Reply #9 on: July 07, 2005, 05:06:27 PM »
Daron, *lol* Yeah I do that too.

But, that code I posted was just a stupid example. Its not very efficient, I was just trying to make a point with that code. The point being that the task can be solved about a million diff ways but if you write down what you want to do; you can code the solution almost the same way as you wrote it down.

For instance: Take what our friend "StarGazer" wrote in the request.

> What I want it to do is grab the first item in the just dump it into a
> list as the first element. Then reading the next line in I want to
> compare it to the list to see if it's the same, if it is then just
> skip it. If not append it to the list. Then go to the next line and
> compare that one to the list. Now that list can be just one or several
> elements that need to be compared.

Now take a look at my code. Im doing almost exactly what he said. (Basicy I translated his words into Autolisp code.)                                                                          

Okay, im done ranting/taching/preaching/etc for da-day.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

LE

  • Guest
Re: list comparison
« Reply #10 on: July 07, 2005, 05:18:28 PM »
This will return the position and the item, and stop evaluating once one item is found.

Code: [Select]

(setq lst1 '(1 11))
(setq lst2 '(5 11 45))

(vl-some '(lambda (i / pos)
   (if (setq pos (vl-position i lst1))
     (list pos i)))
lst2)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
list comparison
« Reply #11 on: July 07, 2005, 05:36:43 PM »
Wasn't Daron looking for a result that indicated the status of each member in the first list, like '(nil t)? Did I misunderstand (again)?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

LE

  • Guest
list comparison
« Reply #12 on: July 07, 2005, 05:46:39 PM »
Quote from: MP
Wasn't Daron looking for a result that indicated the status of each member in the first list, like '(nil t)? Did I misunderstand (again)?


Do not know Michael, to me he wants to find a match an item being on both lists.

Well, I'll wait for his reply.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
list comparison
« Reply #13 on: July 07, 2005, 05:55:23 PM »
Hey that's very cool..

Code: [Select]
_$ (setq lst1 '(1 11 3 6 7))
(setq lst2 '(5 21 18 7 11 45))
(1 11 3 6 7)
(5 21 18 7 11 45)
_$ (vl-some '(lambda (i) (member i lst1)) lst2)
(7)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
list comparison
« Reply #14 on: July 07, 2005, 05:57:04 PM »
Welll ... I went back and read his question and I think I am wrong, maybe he wants an overall result of nil or t ro reflect whether any item in the first list exists in the second.

Something like --

Code: [Select]
(vl-some
   '(lambda (item) (and (member item list2)))
    list1
)

BTW, does LE = Luis Esquivel?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: list comparison
« Reply #15 on: July 07, 2005, 05:59:22 PM »
Quote from: daron
I want to compare these lists to return t or nil if either number in the first list is = to any number in the second list.


I though he just wanted to know if there were any items in the lists that matched.
So at the first match, return a non nil result.

That's the way I read the request.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
list comparison
« Reply #16 on: July 07, 2005, 06:30:09 PM »
Quote from: MP
 ......... BTW, does LE = Luis Esquivel?


That sure looks like something Luis would post :)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

LE

  • Guest
list comparison
« Reply #17 on: July 07, 2005, 10:38:02 PM »
Yes;

Is me.... whatever is left :)

daron

  • Guest
list comparison
« Reply #18 on: July 08, 2005, 07:43:23 AM »
What MP gave worked perfectly. I'm sure what LE gave and CAB would work as well, since if you get a return it works in a cond statement and if there aren't any matches, you'd return nil.

Yes, all I wanted was to see if one list contained a value equal to that in another list. Didn't really care about the output as long as cond could translate it to the desired results. Sorry for not being more clear. Heh, lack of clarity brings on some really interesting results and about 100 different ways to skin the same cat. Thanks for all your efforts. Hopefully, I'll be able to glean the knowledge contained therein.

BTW, welcome Luis Esquivel. What brings you about these parts, if you don't mind me asking?

JohnK

  • Administrator
  • Seagull
  • Posts: 10637
list comparison
« Reply #19 on: July 08, 2005, 08:57:02 AM »
Hey i didnt know we were making a challange outa this?! ...Hold on a sec.


***
Okay im back.

Matt Stachoni once waxed my butt with a nifty lil app kinda along these lines. So... Im gonna take the "Matt route" on this one and hopefully wax someones butt. *gack* Okay that didnt sound so good?! But you know what i mean! *click* What dahell did you just say?!

Darn, i cant find his code, but i think i re-created it. (I'll look for it later)

Code: [Select]
(defun rip-n-flip (lm lc / l-m cntr)
  (setq cntr (length lc) l-m (mapcar 'list lm))
  (while (> cntr -1)
    (setq l-m (subst nil (list (nth cntr lc)) l-m))
    (setq cntr (1- cntr))
    (apply 'append l-m)
  )
)


[] (setq li-m '(1 2 3 4 5 6 7 8 9 0) li-c '(1 2 5))
[] (rip-n-flip li-m li-c)
>> (3 4 6 7 8 9 0)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

daron

  • Guest
list comparison
« Reply #20 on: July 08, 2005, 09:27:28 AM »
I believe >this< is what you were looking for.

Nice app., but I think it's doing the opposite of what I was looking for. Yours seems to return the items that are unique to both lists. Certainly usable in a different situation.

JohnK

  • Administrator
  • Seagull
  • Posts: 10637
list comparison
« Reply #21 on: July 08, 2005, 09:42:53 AM »
yeah, that's it. That lil peice of code floored me. *Thinking at the time: WOW, its so simple, so clean, so efficient! Awesome!*

yes Daron, thats the point.

Code: [Select]
[] (setq li-m '(1 2 3 4 5 6 7 8 9 0) li-c '(1 2 5))
;; set up

[] (setq test (rip-n-flip li-m li-c))
;; which will return: (3 4 6 7 8 9 0)

(cond
  ((eq (length test) (length li-m))
   "*ERROR* No matches found!")
  ((< (length test) (length li-m))
   "Matches found, I can now process the information..."))
;; test the results to see if a match was found.


This would be good for several reasons.
1. You can test to see if there are matches.
2. Ultimatily you can see all the matches and the remaining.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

whdjr

  • Guest
list comparison
« Reply #22 on: July 08, 2005, 10:28:02 AM »
Here's another link to some more lists talks we've had recently.

daron

  • Guest
list comparison
« Reply #23 on: July 08, 2005, 11:02:48 AM »
Well, offerings abound. Thanks.

LE

  • Guest
list comparison
« Reply #24 on: July 08, 2005, 11:06:13 AM »
Quote from: daron

BTW, welcome Luis Esquivel. What brings you about these parts, if you don't mind me asking?


Thank you,

Just want it to share whatever I can of what I know about customization and whenever is possible.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
list comparison
« Reply #25 on: July 08, 2005, 11:24:55 AM »
Welcome Louis.
Glad to have aboard.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

daron

  • Guest
list comparison
« Reply #26 on: July 11, 2005, 10:59:53 AM »
Quote from: Se7en
...
Code: [Select]
(defun rip-n-flip (lm lc / l-m cntr)
  (setq cntr (length lc) l-m (mapcar 'list lm))
  (while (> cntr -1)
    (setq l-m (subst nil (list (nth cntr lc)) l-m))
    (setq cntr (1- cntr))
    (apply 'append l-m)
  )
)


[] (setq li-m '(1 2 3 4 5 6 7 8 9 0) li-c '(1 2 5))
[] (rip-n-flip li-m li-c)
>> (3 4 6 7 8 9 0)

John, I've been studying this piece this morning and found a couple of things that might be needed. First item and this is a small item. Please tell me if I'm off my rocker here, but the way you're starting your counter off, starts you one above the nth value of the list. Wouldn't it make sense to start 1- the length of the list? This way the procedure doesn't have to process more than necessary. As well, instead of (apply 'append l-m) within each run of while, wouldn't it make sense to slap that down one time after you have a list with all your nil's in it? It just seems to me that it would speed up execution, not that it's slow or anything. It just seems that it would be cleaner code if it were. I'm sure this was just a slapped together, get us all thinking and learning procedure, but this is just my feedback. Anyway, here's what I did to tidy it up a bit. Just wanted to show the class my work.
Code: [Select]

(defun rip-n-flip (lm lc / l-m cntr)
     (setq cntr (1- (length lc))
  l-m (mapcar 'list lm)
     )
     (while (> cntr -1)
 (setq l-m (subst nil (list (nth cntr lc)) l-m))
 (setq cntr (1- cntr))
     )
 (apply 'append l-m)
)


Of course, I like this code and I'm one who can't leave well enough alone, so...
Code: [Select]
(defun rip-n-flip2 (lm lc / l-m)
     (setq l-m (mapcar 'list lm))
     (foreach item lc
 (setq l-m (subst nil (list item) l-m))
     )
     (apply 'append l-m)
)

To me, that's just easier to understand. Less is more, ya know.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
list comparison
« Reply #27 on: July 11, 2005, 11:13:48 AM »
This is the way I'd handle the counter.
Code: [Select]
(defun rip-n-flip (lm lc / l-m cntr)
  (setq cntr (length lc)
        l-m  (mapcar 'list lm)
  )
  (while (> (setq cntr (1- cntr)) -1)
    (setq l-m (subst nil (list (nth cntr lc)) l-m))
  )
  (apply 'append l-m)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

daron

  • Guest
list comparison
« Reply #28 on: July 11, 2005, 11:26:48 AM »
Not to split hairs here, but I believe that Stig taught a lesson once about proper use and handling of variables and related it to having to go to the store to buy a bag of salt everytime you want to use salt, as opposed to using the salt you already have. Anyway, setting the counter each time the way you have it there CAB is similar to the buying the bag each time you want to use it. Plus, if we have lists, why do we need to worry about counters at all? Wouldn't my second version work faster and read easier than having counters and using while at all?

Anybody have those timers handy and want to run some tests on all these codes?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
list comparison
« Reply #29 on: July 11, 2005, 11:49:12 AM »
I wasn't saying that was the best code for the job. You revised
John's code addressing the counter starting value. I just said
I would handle that particular code in a different way.
As you stated the foreach is easer to read & I agree.

As for "proper use and handling of variables" I haven't a clue what you mean.
Perhaps a link to that thread or further explanation.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

LE

  • Guest
list comparison
« Reply #30 on: July 11, 2005, 12:08:57 PM »
Why not use this? or am I missing something?

Code: [Select]

(vl-remove-if '(lambda (i) (vl-position i li-c)) li-m)

JohnK

  • Administrator
  • Seagull
  • Posts: 10637
list comparison
« Reply #31 on: July 11, 2005, 12:17:37 PM »
Yes daron, your right. great catches. But yes, I did just slap it together. *blush* I typed it all on command line and just tested it there. Sorry man.

I still havent made my test to see what is faster -ie mapcar, foreach, vl-for.., while, etc. I would like to do some testing to see the speed of these.  ...I'm almost positive that mapcar is recursive in nature and i'd be willing to bet that foreach is not. Anyways im just babbling on here.

Thanx for the catches.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10637
list comparison
« Reply #32 on: July 11, 2005, 12:25:27 PM »
Quote from: LE
Why not use this? or am I missing something?

Code: [Select]

(vl-remove-if '(lambda (i) (vl-position i li-c)) li-m)


Oho, good one! ...Nope dosnet look to me like your missing a thing.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

daron

  • Guest
list comparison
« Reply #33 on: July 11, 2005, 01:16:45 PM »
Quote from: CAB
As for "proper use and handling of variables" I haven't a clue what you mean.
Perhaps a link to that thread or further explanation.

Salt from my own wound. Also, "proper use..." is poor wording on my part. I don't mean to imply that you shouldn't do it that way. Who am I to say how something should or shouldn't be done. I was only wanting to point out that it might be better left as a collected variable only once and not have to reset that one each time. Very similar in nature to having the (apply 'append ...) run each time you run through each item in the test list I would think. Setting or running it once seems to be the most logical way to do it for me.

Oh, Luis, I've wanted to use vl-remove-if as it seeems it would work, but I've got some other things to think about. It appears that my company might be switching to Intellicad and I'm not sure how up to par ICAD is in the VL- functions, so I'm trying to code so I don't have to rework it if(when) that happens. I'm hoping it doesn't, but I've got to be on guard.

LE

  • Guest
list comparison
« Reply #34 on: July 11, 2005, 01:27:53 PM »
Quote from: daron

Oh, Luis, I've wanted to use vl-remove-if as it seeems it would work, but I've got some other things to think about. It appears that my company might be switching to Intellicad and I'm not sure how up to par ICAD is in the VL- functions, so I'm trying to code so I don't have to rework it if(when) that happens. I'm hoping it doesn't, but I've got to be on guard.


OK... 10-4

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
list comparison
« Reply #35 on: July 11, 2005, 03:18:52 PM »
Time trials:
I can not account for the disparity in the results.
Perhaps an interrupt on my computer system?
Command: test
Elapsed time: 1.112000 seconds for rip-n-flip1
Elapsed time: 1.051000 seconds for rip-n-flip2
Command:
Command: test
Elapsed time: 1.082000 seconds for rip-n-flip1
Elapsed time: 1.142000 seconds for rip-n-flip2
Command:
Command: test
Elapsed time: 1.042000 seconds for rip-n-flip1
Elapsed time: 1.051000 seconds for rip-n-flip2
Command:
Command: test
Elapsed time: 1.042000 seconds for rip-n-flip1
Elapsed time: 1.122000 seconds for rip-n-flip2
Command:
Command: test

Elapsed time: 1.062000 seconds for rip-n-flip1
Elapsed time: 1.051000 seconds for rip-n-flip2
Command:
Command: test
Elapsed time: 1.051000 seconds for rip-n-flip1
Elapsed time: 1.152000 seconds for rip-n-flip2
Command:
Command: test
Elapsed time: 1.041000 seconds for rip-n-flip1
Elapsed time: 1.072000 seconds for rip-n-flip2
Command:
Command: test
Elapsed time: 1.051000 seconds for rip-n-flip1
Elapsed time: 1.052000 seconds for rip-n-flip2
Command:
Command: test
Elapsed time: 1.051000 seconds for rip-n-flip1
Elapsed time: 1.051000 seconds for rip-n-flip2
Command: test

Elapsed time: 1.101000 seconds for rip-n-flip1
Elapsed time: 1.072000 seconds for rip-n-flip2
Elapsed time: 2.554000 seconds for LE
Elapsed time: 2.223000 seconds for MP

Command:
Command: test

Elapsed time: 1.051000 seconds for rip-n-flip1
Elapsed time: 1.072000 seconds for rip-n-flip2
Elapsed time: 2.543000 seconds for LE
Elapsed time: 2.233000 seconds for MP

Command:
Command: test

Elapsed time: 1.052000 seconds for rip-n-flip1
Elapsed time: 1.071000 seconds for rip-n-flip2
Elapsed time: 2.544000 seconds for LE
Elapsed time: 2.253000 seconds for MP

Command:
Command: test

Elapsed time: 1.052000 seconds for rip-n-flip1
Elapsed time: 1.181000 seconds for rip-n-flip2
Elapsed time: 2.563000 seconds for LE
Elapsed time: 2.264000 seconds for MP

Command:
Command: test

Elapsed time: 1.072000 seconds for rip-n-flip1
Elapsed time: 1.091000 seconds for rip-n-flip2
Elapsed time: 2.564000 seconds for LE
Elapsed time: 2.254000 seconds for MP
Code: [Select]
;;=============================================================
(defun c:test ()
  (setq lst1 '(1 11 3 6 7))
  (setq lst2 '(5 21 18 7 11 45))

  (startTimer)
  (repeat 10000
    (rip-n-flip1 lst1 lst2)
  )
  (endTimer "rip-n-flip1")
  (startTimer)
  (repeat 10000
    (rip-n-flip2 lst1 lst2)
  )
  (endTimer "rip-n-flip2")
  (startTimer)
  (repeat 10000
    (LE lst1 lst2)
  )
  (endTimer "LE")
  (startTimer)
  (repeat 10000
    (MP lst1 lst2)
  )
  (endTimer "MP")
  (princ)
)

(defun rip-n-flip2 (lm lc / l-m)
  (setq l-m (mapcar 'list lm))
  (foreach item lc
    (setq l-m (subst nil (list item) l-m))
  )
  (apply 'append l-m)
)
(defun rip-n-flip1 (lm lc / l-m cntr)
  (setq cntr (length lc)
        l-m  (mapcar 'list lm)
  )
  (while (> (setq cntr (1- cntr)) -1)
    (setq l-m (subst nil (list (nth cntr lc)) l-m))
  )
  (apply 'append l-m)
)


(defun LE (lst1 lst2 / i pos)
  (vl-some '(lambda (i / pos)
              (if (setq pos (vl-position i lst1))
                (list pos i)
              )
            )
           lst2
  )
)

(defun MP (lst1 lst2 / i pos)
  (vl-some
    '(lambda (item) (and (member item list2)))
    list1
  )
)


Code: [Select]
;;=============================================================
(defun startTimer ()
(setq time (getvar "MILLISECS"))
)
;;=============================================================
(defun endTimer (func)
 (setq time (/ (- (getvar "MILLISECS") time) 1000.0))
 (princ (strcat "\nElapsed time: " (rtos time 2 6) " seconds for " func))
  (gc)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

daron

  • Guest
list comparison
« Reply #36 on: July 11, 2005, 03:32:40 PM »
Wow. It's amazing. RNF1 and 2 are quite negligable, which would imply that the placement of the variables or use of them is also negligable. I would think it would take a sizable piece of code to really determine the effects of having variables vs. not having them. What's up with the VL commands? It seems that any time we've tested these things they always take longer.

LE

  • Guest
list comparison
« Reply #37 on: July 11, 2005, 04:51:34 PM »
Now I am totally confused... rewinding myself....

What is the desired results needed?

Code: [Select]

(setq l1 '(1 11 3 6 7))
(setq l2 '(5 21 18 7 11 45))

(7 11) <== this?


I did the test for (rip-n-flip1 lst1 lst2) and (rip-n-flip2 lst1 lst2) and it is returning:

Code: [Select]

(1 3 6) <== or this?


Or just need to know if one item from one list is in the other one, and get a boolean result?

Here are some other functions, not using vlisp:

Code: [Select]

(defun is_member  (l1 l2 / term lth i)
  (setq lth (length l1)
i   0)
  (while (and (< i lth) (not term))
    (if (member (nth i l1) l2)
      (setq term T))
    (setq i (1+ i)))
  term)

(defun members  (l1 l2 / lth i r)
  (setq lth (length l1)
i   0)
  (while (< i lth)
    (if (member (nth i l1) l2)
      (setq r (cons (nth i l1) r)))
    (setq i (1+ i)))
  (reverse r))

daron

  • Guest
list comparison
« Reply #38 on: July 11, 2005, 11:26:58 PM »
I'm sorry Luis. I didn't mean to confuse. The first issue I was having has been resolved. Since se7en (John) posted his Rip-n-Flip programs in here, I decided to keep them in here. The original function was for the purpose of determining whether or not a list item was the same in two different lists and return a boolean value. Today's purpose, I had two selection sets. One would have a certain amount of ss's in a list and the other would have many more items selected by their layer. This would inadvertently collect entities that were also in the first list. I wanted to remove the item from the second list that were in the first list and found John's RNF procedures to be quite successful. I modified it to suit and decided to post my findings and what I learned about it here. Actually, if anyone is confused, it is I.

JohnK

  • Administrator
  • Seagull
  • Posts: 10637
list comparison
« Reply #39 on: July 12, 2005, 10:16:24 AM »
*blink blink* Am I reading that test right? I cant be reading that right! (My proced was faster then LE and MP?!)

Here would be my take on the slower vl issue.

Seeing as the Autolisp intrip. is "built in" to AutoCAD that is gonna be alot faster then requiring the app to refer to the DLL which is VL.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
list comparison
« Reply #40 on: July 12, 2005, 10:28:38 AM »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

daron

  • Guest
list comparison
« Reply #41 on: July 12, 2005, 01:05:31 PM »
Doesn't that just make you feel so good John?

JohnK

  • Administrator
  • Seagull
  • Posts: 10637
list comparison
« Reply #42 on: July 12, 2005, 03:39:57 PM »
Ummm, YES?!
<billy-madison-voice>
I am the smartest man alive!
</billy-madison-voice>

(Im finaly on the "correct" side of a discussion. ...w00t!)

*lol*
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org