#True is only 1, not all True

Everything else that doesn't fall into one of the other PB categories.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

#True is only 1, not all True

Post 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...
oh... and have a nice day.
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: #True is only 1, not all True

Post 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.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: #True is only 1, not all True

Post 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
oh... and have a nice day.
Thorium
Addict
Addict
Posts: 1271
Joined: Sat Aug 15, 2009 6:59 pm

Re: #True is only 1, not all True

Post 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.
User avatar
Michael Vogel
Addict
Addict
Posts: 2677
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: #True is only 1, not all True

Post 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
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: #True is only 1, not all True

Post by Kaeru Gaman »

@MV
... but you are aware, that Boolean Expressions are not at all supported?
oh... and have a nice day.
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Re: #True is only 1, not all True

Post 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.
PB 4.30

Code: Select all

onErrorGoto(?Fred)
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: #True is only 1, not all True

Post 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...
User avatar
idle
Always Here
Always Here
Posts: 5096
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: #True is only 1, not all True

Post 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
User avatar
Demivec
Addict
Addict
Posts: 4091
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: #True is only 1, not all True

Post 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
SCRJ
User
User
Posts: 93
Joined: Sun Jan 15, 2006 1:36 pm

Re: #True is only 1, not all True

Post 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.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: #True is only 1, not all True

Post 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.
oh... and have a nice day.
User avatar
idle
Always Here
Always Here
Posts: 5096
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: #True is only 1, not all True

Post 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    
Jellybean
User
User
Posts: 95
Joined: Wed Aug 24, 2005 7:33 pm

Re: #True is only 1, not all True

Post by Jellybean »

#True is an API constant from windows.h, it doesn't have anything to do with PB's truth values.
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Re: #True is only 1, not all True

Post 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:
Post Reply