Page 1 of 2

#True is only 1, not all True

Posted: Fri Dec 25, 2009 1:59 pm
by Kaeru Gaman
I'm just pondering if this behavious is preferable or could be changed...

Code: Select all

Test = 4711

If Test = #True
  Debug "#True means <>0, it works"
Else
  Debug "#True only means 1, it doesn't work"
EndIf

If Test
  Debug "without comparison, it works"
Else
  Debug "whoo, that's impossible"
EndIf
Yes I know, a direct comparison normally just compares values.

but perhaps it is desirable to let the compiler change some direct

Code: Select all

If (EXPR) = #True
to

Code: Select all

If Not (EXPR) = #False
or some other tweak...

... or if it just is to be made clear that ir's better to use

Code: Select all

If (EXPR)
and

Code: Select all

If Not (EXPR)
without direct comparison...

Re: #True is only 1, not all True

Posted: Fri Dec 25, 2009 3:39 pm
by rsts
Not quite sure I understand the point.

Since #True is a constant, it can only have one value.

And I personally would not want anything <> 0 to test True, for example -1.

But I'm probably missing something elementary :)

No offense intended Mr Gaman.

Best wishes for a happy holiday season.

Re: #True is only 1, not all True

Posted: Fri Dec 25, 2009 3:53 pm
by Kaeru Gaman
sure you are right when you say, #True is a constant, testing against a constant would/should/could mean testing against a single value...

but "= #True" could also be interpreted as "is this true", meaning the same as happening when testing

Code: Select all

If (EXPR)
note that when you test an expression standalone, any value <>0 will be considered "true"...

so I just asked for opinions from the community, what would be more according to form and expectations,
should "= #True" mean "equal to value 1" or "is this true"...


Best wishes from me, too

Re: #True is only 1, not all True

Posted: Fri Dec 25, 2009 3:56 pm
by Thorium
#True is a constant and should be treated as any other constant.
But True as a new keyword could be used for what you want.

Re: #True is only 1, not all True

Posted: Fri Dec 25, 2009 4:14 pm
by Michael Vogel
The statement "True is not #True" is true, isn't it? :lol:

Code: Select all

Macro True(x)
	(x)<>0
EndMacro
Macro False(x)
	(x)=0
EndMacro

If True(7=1)
	Debug "7=1 is true"
EndIf
If False(7=1)
	Debug "7=1 is false"
EndIf

If True(7>1)
	Debug "7>1 is true"
EndIf

Re: #True is only 1, not all True

Posted: Fri Dec 25, 2009 4:20 pm
by Kaeru Gaman
@MV
... but you are aware, that Boolean Expressions are not at all supported?

Re: #True is only 1, not all True

Posted: Fri Dec 25, 2009 4:44 pm
by AND51
Nice question, Kaeru Gaman.

In my opinion, it depends on wether you consider "#True" being "a constant with the value 1" or "true".

Currently, "#True" seems to be a constant with the value 1, because this does not work:

Code: Select all

If 42 = #True
   Debug "yes"
EndIf
But this If-Statement is equivalent to this statement:

Code: Select all

If 42
   Debug "yes"
EndIf
You know, if you just leave out the operator and the right operand, an If-Statement just checks, wether the expression is true or false. This is what the second piece of code demonstrates; hence, the first piece of code should behave the same way.

Re: #True is only 1, not all True

Posted: Fri Dec 25, 2009 4:52 pm
by djes
The first code means a comparison between two values.
The second is an implicit test if the value <> 0. It's the normal behaviour of a compiler. No problem there...

Re: #True is only 1, not all True

Posted: Fri Dec 25, 2009 10:47 pm
by idle
if want Boolean evaluations

Code: Select all

Macro expr(expr)
  Not(Not(expr))
EndMacro

test = 4715

If expr(Test) = #True
  Debug "#True now means <> 0, it works"
EndIf

Re: #True is only 1, not all True

Posted: Sat Dec 26, 2009 4:07 am
by Demivec
I think it would be simpler to say #True <> #False.

Code: Select all

Test = 4711
;Test = 25

If Test <> #False
  Debug "#True means <>0, it works"
Else
  Debug "#False means = 0"
EndIf

If Test
  Debug "True, without comparison."
Else
  Debug "False, without comparison"
EndIf

;more complex example with a comparison and boolean expressions
If (Test > 10 And Test <> 25) <> #False
  Debug "#True means <>0, it works"
Else
  Debug "#False means = 0"
EndIf

Re: #True is only 1, not all True

Posted: Sat Dec 26, 2009 11:08 am
by SCRJ
What Kaeru Gaman wants is basically 'true' boolean expression evaluation
as it's available in other languages such as C# or Java.
'true' and 'false' are completely separated from numbers.

Code: Select all

Define myVar.i = 10
If myVar
    Debug "True"
EndIf
That wouldn't work in those languages because 10 is not true, it's just 10.
You have to check it explicitly:

Code: Select all

Define myVar.i = 10
If myVar <> 0 ; Now it's a full boolean expression.
    Debug "True"
EndIf
In my opinion, that is a much cleaner way to handle expressions.
But that would require that PB supports boolean expressions first.

Re: #True is only 1, not all True

Posted: Sat Dec 26, 2009 11:21 am
by Kaeru Gaman
nope, what I wanted was just pondering / philosophizing about the meaning of "= #True"

Boolean Expressions are at the gates, some Bool() function will be implemented in a future version, soon 4.5 or maybe later, but it is promised.

And I really like the possibility in PB to check a Returnvalue for success just by doing

Code: Select all

If CreateImage(...
and sure I don't want anything to be changed there.

Re: #True is only 1, not all True

Posted: Wed Dec 30, 2009 5:59 am
by idle
Well while people are waiting for Boolean expressions you can use the macro
The only reason you need to use two "Not" is just due to how the compiler deals to the expressions, if you don't use the nots it just doesn't work in some circumstances.

Code: Select all

Macro expr(expr)
  Not(Not(expr))
EndMacro

test = 4715

If expr(Test) 
  Debug "#True now means <> 0, it works"
EndIf

str$ = "blar" 
str1$ = "blar" 
str2$ = ""

If expr(str$ = str1$ And str2$) 
  Debug "yep" 
Else 
  Debug "nope"
EndIf 

If expr(str2$ Or str$ And str1$)
   Debug "True"
Else 
   Debug "false" 
EndIf    

Re: #True is only 1, not all True

Posted: Sun Jan 03, 2010 10:27 pm
by Jellybean
#True is an API constant from windows.h, it doesn't have anything to do with PB's truth values.

Re: #True is only 1, not all True

Posted: Sun Jan 03, 2010 10:46 pm
by utopiomania
#TRUE is a constant defined as NOT #FALSE. True can be anything as long as it is not false, and false
can be anything as long as it is not true.

Simple as that. :roll: