TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: rude dog on February 11, 2004, 02:33:23 PM

Title: Already choosen...or is it?
Post by: rude dog on February 11, 2004, 02:33:23 PM
Need help understanding how code can search a list and find items that have been choosen (and prompt "duplicate objects will be ignored")  twice ...can any one offer a small simple routine for me to study...I have looked @ others code and the help menu but still can make the connection. :x
Title: Re: Already choosen...or is it?
Post by: Matt Stachoni on February 11, 2004, 02:36:18 PM
Quote from: Rude Dog
Need help understanding how code can search a list and find items that have been choosen (and prompt "duplicate objects will be ignored")  twice ...can any one offer a small simple routine for me to study...I have looked @ others code and the help menu but still can make the connection. :x


Normally, the trick is to build the list using a test to see if it's a member already:
Code: [Select]
(if (not (member x lst))
  (setq lst (cons x lst))
)
However, I would need to see your routine to fully understand "have been chosen."
Do you mean selected, as in a selction set?
Title: Already choosen...or is it?
Post by: rude dog on February 11, 2004, 03:03:53 PM
Matt,
(if (not (member x lst))
  (setq lst (cons x lst))
)

you hit it right on the head...please eloborate what each step does
(if and (not ...togethter kinda throw me  :oops:
Title: Already choosen...or is it?
Post by: daron on February 11, 2004, 03:14:33 PM
All if and not together means that if the test function returns true, not wrapped around it changes t to nil. So, if the member of x is NOT a lst(list) then set lst to cons...
Title: Already choosen...or is it?
Post by: Mark on February 11, 2004, 03:37:04 PM
Let me add to this. Break down the commands that Matt showed us and watch what happens.
Code: [Select]

 - create a list
Command: (setq lst '(1 2 3 4))
(1 2 3 4)

Command: (member 3 lst)
(3 4) <- notice member return something

- create 'x'
Command: (setq x 5)
5

Command: (member x lst)
nil <- nope x is _not_ in the list

Command: (not (member x lst))
T <- returns T (true) because 5 is not in the list

Command: (setq lst (cons x lst))
(5 1 2 3 4) <- construct a new list and add 'x' to it

- create 'x'
Command: (setq x 6)
6

- now put it all together
Command: (if (not (member x lst))(setq lst (cons x lst)))
(6 5 1 2 3 4)
Title: Already choosen...or is it?
Post by: Anonymous on February 11, 2004, 04:02:43 PM
Got it dude:D  :!:  :wink:
Title: Already choosen...or is it?
Post by: rude dog on February 11, 2004, 04:03:53 PM
me again....above