Author Topic: Can't make (if (or work  (Read 3468 times)

0 Members and 1 Guest are viewing this topic.

Joe

  • Guest
Can't make (if (or work
« 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

subbup

  • Guest
Can't make (if (or work
« Reply #1 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)))
  )

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Can't make (if (or work
« Reply #2 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?
TheSwamp.org  (serving the CAD community since 2003)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Can't make (if (or work
« Reply #3 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.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Can't make (if (or work
« Reply #4 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"
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Joe

  • Guest
Can't get it to work
« Reply #5 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.

hendie

  • Guest
Can't make (if (or work
« Reply #6 on: July 07, 2004, 04:15:42 PM »
now there's civility and politeness for you.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Can't make (if (or work
« Reply #7 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...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie