(/= var var) returns True

(/= var var) returns True

Anonymous
Not applicable
1,188 Views
6 Replies
Message 1 of 7

(/= var var) returns True

Anonymous
Not applicable

Why does this return True?

 

_$ (/= (GETVAR "INSBASE") (GETVAR "INSBASE"))
T

 
Say what now? TRYING to get my base point checked and set to (0,0,0) if it's not.
 
I.E.
(VL-LOAD-COM)
(DEFUN C:SOMFUNC( / ZEROLIST)
  (SETQ ZEROLIST (LIST 0.0 0.0 0.0))
  (COND
    ((/= (GETVAR "INSBASE") ZEROLIST)(SETVAR "INSBASE" ZEROLIST))
(T NIL) (PRINC) )
0 Likes
Accepted solutions (1)
1,189 Views
6 Replies
Replies (6)
Message 2 of 7

doaiena
Collaborator
Collaborator
Accepted solution

Use equal to do this comparison.

(equal (GETVAR "INSBASE") (GETVAR "INSBASE"))
(not (equal (GETVAR "INSBASE") (GETVAR "INSBASE")))
Message 3 of 7

Anonymous
Not applicable

That's twice I got caught with that "equal" operator in the past month or so.

 

Is this over complicated?

. . .
(COND ((/= (GETVAR "CLAYER") 0)(SETVAR "CLAYER" "0")) ((NOT (EQUAL (GETVAR "INSBASE") ZEROLIST)) (SETVAR "INSBASE" (LIST 0 0 0))) (T NIL) )
. . .

I feel like there's a real simple way around that NOT operator. . . Either way, this works.

 

Thanks @doaiena

0 Likes
Message 4 of 7

Shneuph
Collaborator
Collaborator

It seems like no matter what you want INBASE to be set to 0,0,0.  So, what if it's already 0,0,0 why check?  Just set it to 0,0,0 whether it is or not?

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
Message 5 of 7

doaiena
Collaborator
Collaborator

@Shneuph is right in your case. You could just set the variables without checking their current values. Just these two lines:

(setvar "CLAYER" "0")
(setvar "INSBASE" '(0 0 0))


Also on another note, your cond statement won't work the way you intend to. cond evaluates from top to bottom, and once it gets a true statement in return, it executes that code and skips the rest. That means that the way you have written your code, if your current layer isn't "0" then it will be set to "0" and the cond statement will exit, without even checking for the insbase variable. 

If you want to check for multiple variables you should use an if progn statement, or some sort of loop over a list of variables.

And the last thing:

...
(COND
    ((/= (GETVAR "CLAYER") 0)(SETVAR "CLAYER" "0"))
...

This statement will always return true, because (getvar "CLAYER") returns a string, and you are comparing it to an integer. That means that in your code the current layer will always be set to "0" and it will never check for the insbase variable.

 

0 Likes
Message 6 of 7

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:
. . .
(COND ((/= (GETVAR "CLAYER") "0")(SETVAR "CLAYER" "0")) ((NOT (EQUAL (GETVAR "INSBASE") ZEROLIST)) (SETVAR "INSBASE" (LIST 0 0 0))) (T NIL) )
. . .

....


 

I don't think (cond) is the right thing to use here.  It makes one property dependent on another un-related one.  If the current Layer isn't 0, it will see that condition as True, and will set it to 0, and then because it's found a non-nil condition by then, not go on to check the INSBASE value at all.

 

Also, that  (T nil)  line is kind of pointless -- just omit it, because (cond) will return nil without it, if all the conditions tested for did so.

 

But I agree that there's really no need to test for these things, if you want them to have a certain value in any case.  Just set them to that, whether they are already or not.  All of your code window could be replaced by just:

 

(SETVAR 'CLAYER "0")

(SETVAR 'INSBASE '(0 0 0))

Kent Cooper, AIA
Message 7 of 7

Anonymous
Not applicable

That's much easier. 

Thanks for all the input.

0 Likes