TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started 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
-
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:(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?
-
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:
-
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...
-
Let me add to this. Break down the commands that Matt showed us and watch what happens.
- 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)
-
Got it dude:D :!: :wink:
-
me again....above