PDA

View Full Version : Equal, Eq or Something Else?


BoKirra
2008-11-25, 01:38 AM
HI ALL,

The following statements are subtracted from my code.
I'ld like to know if those "eq" are used correctly.
Thanks in advance.


(if (eq (getvar "celtscale") 1)
(setvar "celtscale" 1)
) ;end of if
(if (eq (getvar "cecolor") bylayer)
(setvar "cecolor" "bylayer")
) ;end of if

rkmcswain
2008-11-25, 02:07 AM
The differences between eq, equal, and = are described in acad_dev.chm

Here is an excerpt:

Comparing the eq and equal Functions

If the eq function finds that two lists or atoms are the same, the equal function also finds them to be the same.

Any atoms that the equal function determines to be the same are also found equivalent by eq. However, two lists that equal determines to be the same may be found to be different according to the eq function.

BoKirra
2008-11-25, 05:11 AM
The differences between eq, equal, and = are described in acad_dev.chm

Here is an excerpt:

Comparing the eq and equal Functions

If the eq function finds that two lists or atoms are the same, the equal function also finds them to be the same.

Any atoms that the equal function determines to be the same are also found equivalent by eq. However, two lists that equal determines to be the same may be found to be different according to the eq function.

Thanks.
And sorry for my code stated incorrectly.
Actually, what I wanted to do was
1) If "celtscale" wasn't set to "1", reset it to "1".
2) If "cecolor" wasn't set to "bylayer", reset it to "bylayer".

How to write these "IF" statements?

BTW, yes, the "=", "eq" & "equal" do confuse me.
I'll read the HELP files in details.

irneb
2008-11-25, 06:22 AM
Basically eq checks if 2 things are the same things, especially with lists. You may have 2 lists that have the same values - but they're 2 different lists. In which case eq would return nil, but equal would return T (because they have the same values). E.g.
(setq L1 '(1 2 3) L2 '(1 2 3) L3 L1) ;Setup example lists

;; Check similarity
(eq L1 L2) ;returns nil
(= L1 L2) ;returns nil
(equal L1 L2) ;returns T

;; Check exact same
(eq L1 L3) ;returns T
(= L1 L3) ;returns T
(equal L1 L3) ;returns TFurther to that equal allows for a fuzzy comparison. Eg.(equal 1.1 1.2 0.2) ;Returns T

irneb
2008-11-25, 06:34 AM
As to comparing sysvars, you need to compare them to their true values. E.g. CELTSCALE is a real value so eq would only work for (eq (getvar "CELTSCALE") 1.0), otherwise (equal (getvar "CELTSCALE") 1) would return T ... assuming of course that LTSCALE is set to 1.

CECOLOR returns a string value. So if your colour is set to Red, then (getvar "CECOLOR") will return "1". In this case neither eq or equal will return true when comparing it to the integer value 1. You either convert the string to int with atoi, or rather compare it to a string. Further to that, string comparison is also case sensitive so you might have to use strcase to force into Upper- / Lower case. E.g.(= (strcase (getvar "CECOLOR")) "BYLAYER") ;Returns true, but
(= (getvar "CECOLOR") "bylayer") ;Returns false

ccowgill
2008-11-25, 02:21 PM
HI ALL,

The following statements are subtracted from my code.
I'ld like to know if those "eq" are used correctly.
Thanks in advance.


(if (eq (getvar "celtscale") 1)
(setvar "celtscale" 1)
) ;end of if
(if (eq (getvar "cecolor") bylayer)
(setvar "cecolor" "bylayer")
) ;end of if
the statements above will not give you your desired effect. Everyone else's replies are correct, however you if statements are incorrect.
if you look up IF in the developer help, it will explain how to use it. The first function is what to do if it is true, the second is what to do if it is false. so per your other post in this thread one of the correct ways to display the above code would be:

(if (/= (getvar "celtscale") 1); if getvar is not equal to 1
(setvar "celtscale" 1);do this
();otherwise do this
)
(if (/= (getvar "cecolor") "bylayer"); if getvar is not equal to bylayer
(setvar "cecolor" "bylayer");do this
();otherwise do this
)

BoKirra
2008-11-26, 02:43 AM
1) As to comparing sysvars, you need to compare them to their true values.
2) CELTSCALE is a real value...
3) CECOLOR returns a string value...

It is clear now by highlighting your points.

Thanks again with :beer::beer::beer:

BoKirra
2008-11-26, 02:54 AM
Everyone else's replies are correct, however you if statements are incorrect.
What! everyone's correct but mine?:Oops:hahaha...

if you look up IF in the developer help, it will explain how to use it.
Yes, I need to read "IF" again. Thanks.:beer:

...the correct ways to display the above code would be:

(if (/= (getvar "celtscale") 1); if getvar is not equal to 1
(setvar "celtscale" 1);do this
();otherwise do this
)
(if (/= (getvar "cecolor") "bylayer"); if getvar is not equal to bylayer
(setvar "cecolor" "bylayer");do this
();otherwise do this
)


Yes, it works certainly.
Thanks again.:beer:

ccowgill
2008-11-26, 02:50 PM
What! everyone's correct but mine?:Oops:hahaha...

I'm sorry, what I meant to say was, the if statement, the way it is called, would not change anything, because if the statements you were checking are true, then you are changing the variables to what they already are.

BoKirra
2008-11-27, 12:41 AM
I'm sorry, what I meant to say was, the if statement, the way it is called, would not change anything, because if the statements you were checking are true, then you are changing the variables to what they already are.

Yes, you're right.
I was laughing at what mistakes I made - nothing serious.
And thanks for your help again.:beer::beer::beer: