TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started 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
-
try this one
(if (or (/= a 0)(/= a "DEF"))
(if (not (member a newlist))
(setq newlist (cons a newlist)))
)
-
the statement;
(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?
-
Written another way:
(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.
-
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"
-
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.
-
now there's civility and politeness for you.
-
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...