Page 1 of 1

"Variable = 1 = Function()" is valid syntax?

Posted: Thu Dec 02, 2010 3:31 pm
by c4s
I just had a typo that I didn't noticed because no syntax error was raised:

Code: Select all

Var = 1 = Sign(0)
Debug Var
Isn't this wrong syntax? A bug?

I was pretty confused then and tried a little around... What's with the following:

Code: Select all

a = 1
b = 2
c = 3
a = b = c
Debug a
Debug b
Debug c

Re: "Variable = 1 = Function()" is valid syntax?

Posted: Thu Dec 02, 2010 3:37 pm
by TomS
I would have said it's correct syntax, if it worked as expected.
var would be defined as 1 and then re-defined as 0, or whatever the function may return.
Since this is not the case, I think it's a bug.
The same applies for the second example. Logically a, b and c should be 3.

Re: "Variable = 1 = Function()" is valid syntax?

Posted: Thu Dec 02, 2010 5:27 pm
by inSANE
c4s wrote:

Code: Select all

Var = 1 = Sign(0)
a = b = c
Relating to the syntax, this is quite right.
But it depends on the result you expect, if the result will be what you were looking for.

Usually such a syntax is used to get a #True or #False on the comparison of the 2nd expression.
So, if you want "Var" to be #True, if "1 = Sign(0)" or "a" to be #True if "b = c", this is the common syntax for that.

But PB does not result with a boolean output on such expressions.
However you can use a little macro to get a boolean result out of such a comparison:

Code: Select all

Macro bool_m( expr )
  ( ( expr ) Or #False )
EndMacro

Var = bool_m(1 = Sign(0))
a   = bool_m(b = c)

Debug Var
Debug a

Re: "Variable = 1 = Function()" is valid syntax?

Posted: Thu Dec 02, 2010 8:18 pm
by blueznl