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

Everything else that doesn't fall into one of the other PB categories.
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

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

Post 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
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
User avatar
TomS
Enthusiast
Enthusiast
Posts: 342
Joined: Sun Mar 18, 2007 2:26 pm
Location: Munich, Germany

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

Post 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.
User avatar
inSANE
User
User
Posts: 10
Joined: Tue Nov 16, 2010 3:17 pm

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

Post 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
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

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

Post by blueznl »

( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Post Reply