It is currently Wed Apr 01, 2020 2:52 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: #True is only 1, not all True
PostPosted: Fri Dec 25, 2009 1:59 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Mar 19, 2006 1:57 pm
Posts: 4828
Location: Germany
I'm just pondering if this behavious is preferable or could be changed...
Code:
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:
If (EXPR) = #True
to
Code:
If Not (EXPR) = #False
or some other tweak...

... or if it just is to be made clear that ir's better to use
Code:
If (EXPR)
and
Code:
If Not (EXPR)
without direct comparison...

_________________
oh... and have a nice day.


Top
 Profile  
Reply with quote  
 Post subject: Re: #True is only 1, not all True
PostPosted: Fri Dec 25, 2009 3:39 pm 
Offline
Addict
Addict

Joined: Wed Aug 24, 2005 8:39 am
Posts: 2736
Location: Southwest OH - USA
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: #True is only 1, not all True
PostPosted: Fri Dec 25, 2009 3:53 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Mar 19, 2006 1:57 pm
Posts: 4828
Location: Germany
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:
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: #True is only 1, not all True
PostPosted: Fri Dec 25, 2009 3:56 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Aug 15, 2009 6:59 pm
Posts: 1252
#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.


Top
 Profile  
Reply with quote  
 Post subject: Re: #True is only 1, not all True
PostPosted: Fri Dec 25, 2009 4:14 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Feb 09, 2006 11:27 pm
Posts: 2473
The statement "True is not #True" is true, isn't it? :lol:

Code:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: #True is only 1, not all True
PostPosted: Fri Dec 25, 2009 4:20 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Mar 19, 2006 1:57 pm
Posts: 4828
Location: Germany
@MV
... but you are aware, that Boolean Expressions are not at all supported?

_________________
oh... and have a nice day.


Top
 Profile  
Reply with quote  
 Post subject: Re: #True is only 1, not all True
PostPosted: Fri Dec 25, 2009 4:44 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Oct 15, 2006 8:56 pm
Posts: 1040
Location: Germany
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:
If 42 = #True
   Debug "yes"
EndIf
But this If-Statement is equivalent to this statement:
Code:
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:
onErrorGoto(?Fred)


Top
 Profile  
Reply with quote  
 Post subject: Re: #True is only 1, not all True
PostPosted: Fri Dec 25, 2009 4:52 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2005 2:46 pm
Posts: 1799
Location: Pas-de-Calais, France
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...


Top
 Profile  
Reply with quote  
 Post subject: Re: #True is only 1, not all True
PostPosted: Fri Dec 25, 2009 10:47 pm 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 3488
Location: New Zealand
if want Boolean evaluations

Code:
Macro expr(expr)
  Not(Not(expr))
EndMacro

test = 4715

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


Top
 Profile  
Reply with quote  
 Post subject: Re: #True is only 1, not all True
PostPosted: Sat Dec 26, 2009 4:07 am 
Offline
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 3643
Location: Utah, USA
I think it would be simpler to say #True <> #False.

Code:
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

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: #True is only 1, not all True
PostPosted: Sat Dec 26, 2009 11:08 am 
Offline
User
User

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


Top
 Profile  
Reply with quote  
 Post subject: Re: #True is only 1, not all True
PostPosted: Sat Dec 26, 2009 11:21 am 
Offline
Addict
Addict
User avatar

Joined: Sun Mar 19, 2006 1:57 pm
Posts: 4828
Location: Germany
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:
If CreateImage(...
and sure I don't want anything to be changed there.

_________________
oh... and have a nice day.


Top
 Profile  
Reply with quote  
 Post subject: Re: #True is only 1, not all True
PostPosted: Wed Dec 30, 2009 5:59 am 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 3488
Location: New Zealand
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:
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   


Top
 Profile  
Reply with quote  
 Post subject: Re: #True is only 1, not all True
PostPosted: Sun Jan 03, 2010 10:27 pm 
Offline
User
User

Joined: Wed Aug 24, 2005 7:33 pm
Posts: 95
#True is an API constant from windows.h, it doesn't have anything to do with PB's truth values.


Top
 Profile  
Reply with quote  
 Post subject: Re: #True is only 1, not all True
PostPosted: Sun Jan 03, 2010 10:46 pm 
Offline
Addict
Addict
User avatar

Joined: Tue May 10, 2005 10:00 pm
Posts: 1651
Location: Norway
#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:


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye