Author Topic: Already choosen...or is it?  (Read 4039 times)

0 Members and 1 Guest are viewing this topic.

rude dog

  • Guest
Already choosen...or is it?
« 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

Matt Stachoni

  • Guest
Re: Already choosen...or is it?
« Reply #1 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?

rude dog

  • Guest
Already choosen...or is it?
« Reply #2 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:

daron

  • Guest
Already choosen...or is it?
« Reply #3 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...

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
Already choosen...or is it?
« Reply #4 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)
TheSwamp.org  (serving the CAD community since 2003)

Anonymous

  • Guest
Already choosen...or is it?
« Reply #5 on: February 11, 2004, 04:02:43 PM »
Got it dude:D  :!:  :wink:

rude dog

  • Guest
Already choosen...or is it?
« Reply #6 on: February 11, 2004, 04:03:53 PM »
me again....above