Page 2 of 3
Re: Should this work?
Posted: Wed Oct 21, 2009 4:09 pm
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.
Re: Should this work?
Posted: Wed Oct 21, 2009 4:12 pm
by Kaeru Gaman
!WOW!
Boolean Expressions in PureBasic?
Oct.21st now is a Historic Date.
Re: Should this work?
Posted: Wed Oct 21, 2009 4:20 pm
by Demivec
Kaeru Gaman wrote:!WOW!
Boolean Expressions in PureBasic?
Oct.21st now is a Historic Date.
That goes
double for me!

Re: Should this work?
Posted: Wed Oct 21, 2009 4:21 pm
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.

Thanks in advance!
Regards, Little John
Re: Should this work?
Posted: Wed Oct 21, 2009 4:58 pm
by Fred
Please note the
"change in a future version", so don't whine if it doesn't make it for 4.50

Re: Should this work?
Posted: Wed Oct 21, 2009 5:23 pm
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
Re: Should this work?
Posted: Sat Oct 31, 2009 2:23 pm
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.

Regards, Little John
Re: Should this work?
Posted: Sat Oct 31, 2009 8:46 pm
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...
Re: Should this work?
Posted: Sat Oct 31, 2009 10:17 pm
by Mistrel
Demivec wrote:That goes
double for me!

You could say we're
floating on air.

Re: Should this work?
Posted: Sat Oct 31, 2009 11:18 pm
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

Re: Should this work?
Posted: Sat Oct 31, 2009 11:28 pm
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.
Re: Should this work?
Posted: Sat Oct 31, 2009 11:34 pm
by Kaeru Gaman
ah, wonderful. thank you very much.
Re: Should this work?
Posted: Sun Nov 01, 2009 2:41 am
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?
Re: Should this work?
Posted: Sun Nov 01, 2009 11:45 am
by Fred
May be, but it will be much clearer like that.
Re: Should this work?
Posted: Sun Nov 01, 2009 1:14 pm
by nco2k
whoa.. thats some good news. thanks!
c ya,
nco2k