Should this work?

Just starting out? Need help? Post your questions and find answers here.
Fred
Administrator
Administrator
Posts: 18252
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Should this work?

Post by Fred »

We plan to change this in a future version. After some reflexion with Fr34k, we decided to add a compiler directive called Boolean() and accpet such expression only within it. All other use will raise compiler error.

Example:

Code: Select all

Test = Boolean(a = 10 And c = 20) ; Test will contains 0 or 1 depending of the test.
Test = a = 10 And c = 20 ; Test will raise a compiler error.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: Should this work?

Post by Kaeru Gaman »

!WOW! :shock:

Boolean Expressions in PureBasic?
Oct.21st now is a Historic Date.
oh... and have a nice day.
User avatar
Demivec
Addict
Addict
Posts: 4270
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Should this work?

Post by Demivec »

Kaeru Gaman wrote:!WOW! :shock:

Boolean Expressions in PureBasic?
Oct.21st now is a Historic Date.
That goes double for me! :D
Little John
Addict
Addict
Posts: 4791
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Should this work?

Post by Little John »

Fred wrote:Example:

Code: Select all

Test = Boolean(a = 10 And c = 20) ; Test will contains 0 or 1 depending of the test.
Test = a = 10 And c = 20 ; Test will raise a compiler error.
Very cool. 8)
Thanks in advance!

Regards, Little John
Fred
Administrator
Administrator
Posts: 18252
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Should this work?

Post by Fred »

Please note the "change in a future version", so don't whine if it doesn't make it for 4.50 ;)
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: Should this work?

Post by rsts »

Fred wrote:. . . so don't whine if it doesn't make it for 4.50 ;)
Fred, you give us so much already, we should NEVER whine :)

cheers
Little John
Addict
Addict
Posts: 4791
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Should this work?

Post by Little John »

I think we can already now take advantage of a macro for this purpose, which can have the same name.

Code: Select all

Macro boolean (_expression_)
   ((_expression_) Or #False)
EndMacro

;-- Demo
Define a, b, c

a = boolean(Not #False)
Debug a

Debug "--------"

c = 10
a = boolean(b=c)
Debug a
Debug b
Debug c
The macro does no error checking, but it can help us in the following respects:
  • Forgotten to enclose 'Not #False' in braces:
    a = Not #False ; doesn't work
    a = boolean(Not #False) ; does work
  • The case discussed here:
    a = b = c ; doesn't work as expected
    a = boolean(b=c) ; does work as expected
  • From some people's point of view, using this macro might increase readability.
  • When the compiler directive Boolean() will be introduced into PureBasic, it is already in our code at the proper place. :D
Regards, Little John
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: Should this work?

Post by Kaeru Gaman »

I just stumbled over this:
Fred wrote:We plan to change this in a future version. After some reflexion with Fr34k, we decided to add a compiler directive called Boolean() and accpet such expression only within it. All other use will raise compiler error.
if it will be a compiler directive, does this mean it will be evaluated at compiletime and can only compare constants?

because, Boolean Expressions are really useful to work with variables...
oh... and have a nice day.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: Should this work?

Post by Mistrel »

Demivec wrote:That goes double for me! :D
You could say we're floating on air. ;)
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Should this work?

Post by luis »

Kaeru Gaman wrote: if it will be a compiler directive, does this mean it will be evaluated at compiletime and can only compare constants?
because, Boolean Expressions are really useful to work with variables...
Yes, this is unclear to me to. How could be a compiler directive ? To me EnableExplicit is a compiler directive.

BTW: I'm using a BOOL() macro in just the same way in my code :)
"Have you tried turning it off and on again ?"
Fred
Administrator
Administrator
Posts: 18252
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Should this work?

Post by Fred »

It's a compiler directive which will add the needed ops to returns a boolean values. It will indeed work with any expressions.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: Should this work?

Post by Kaeru Gaman »

ah, wonderful. thank you very much.
oh... and have a nice day.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: Should this work?

Post by Mistrel »

Is it necessary to have the Boolean keyword? Wouldn't just surrounding an assignment operation be enough to evaluate it as an expression?
Fred
Administrator
Administrator
Posts: 18252
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Should this work?

Post by Fred »

May be, but it will be much clearer like that.
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: Should this work?

Post by nco2k »

whoa.. thats some good news. thanks! :shock:

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
Post Reply