TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Joe on July 07, 2004, 03:41:36 AM

Title: Can't make (if (or work
Post by: Joe on July 07, 2004, 03:41:36 AM
I have been unsuccessful using the following:

(if (or (/= a "0")(/= a "DEF"))
      (if (not (member a newlist))        
            (setq newlist (cons a newlist)))
 
    )

It just seems to completely ignore the conditions. If I remove the OR and one condition, it works just fine. What am I missing?

Thanks, Joe
Title: Can't make (if (or work
Post by: subbup on July 07, 2004, 04:36:54 AM
try this one

(if (or (/= a 0)(/= a "DEF"))
(if (not (member a newlist))
(setq newlist (cons a newlist)))
  )
Title: Can't make (if (or work
Post by: Mark on July 07, 2004, 07:10:53 AM
the statement;
Code: [Select]
(or (/= a "0") (/= a "DEF"))
is always going to return T since 'a' cannot be both "0" and 'DEF" is that what you want?

OR returns T if any of the arguments are T.

What are you trying to accomplish?
Title: Can't make (if (or work
Post by: CAB on July 07, 2004, 08:09:52 AM
Written another way:
Code: [Select]
(if (and(not (member a '("0" "DEF")))
        (not (member a newlist))
     )
    (setq newlist (cons a newlist))
)


What you are saying here is
if 'a' is anything but the letter zero OR "DEF" AND not already in the list
then add the value of 'a' to the list

Is that what you wanted to happen.
Title: Can't make (if (or work
Post by: Keith™ on July 07, 2004, 09:06:34 AM
and / or is completely misunderstood by many people and as a result is largely left unused, those who attempt to use it frequently have problems because of the dynamic nature of our thinking and the linear nature of computing (at least that is what someone smarter than me said one time)

if we say (or (/= a "0")(/= a "DEF")) what we think we are saying is if a does not have a value equal to "0" or "DEF" inclusive, meaning that we think we are saying it cannot equal "0" and it cannot equal "DEF" as follows:
(setq a "DEF")
(/= a "0") true
(/= a "DEF") false

So since we think that one is false, the result is false, however the result is true....


what the computer sees is if either of the or arguments is true, then the statement is true

that is where you have the problem... replace or with and, then you will run the code only if the value is neither "0" or "DEF"
Title: Can't get it to work
Post by: Joe on July 07, 2004, 03:23:59 PM
Thanks, everyone. I see that what I thought I was asking for (if it doesn't equal "0" or "DEF" then proceed was wrong. I now understand the AND in this use. I tried it and it worked perfectly. Thanks again.
Title: Can't make (if (or work
Post by: hendie on July 07, 2004, 04:15:42 PM
now there's civility and politeness for you.
Title: Can't make (if (or work
Post by: Keith™ on July 07, 2004, 04:20:39 PM
Glad to help.... and if you would take the time to register, you might find that while we sometimes are a brash bunch, we do have our good side too... well most of us do anyway...