Page 2 of 3

Re: Should this work?

Posted: Mon Oct 19, 2009 11:52 pm
by Olliv
Thank you citystate. I find it's shame using such these terms. It's a reflex which can drive into wrong judgements. I use them too in french but it's very rare. In this way, apparently (I saw the link of dhouston), I don't see where is the 'bull' here. Because, there is a real problem with 'a = b = c' even if I and others would want this to mean a specific function (like C compiler, in one kind or like old Basic compiler, in an other kind).

Logically, 'a = b = c = d' creates a syntax error at my compiler. So, there is certainly a little bug to solve in the compiler.

Re: Should this work?

Posted: Tue Oct 20, 2009 9:21 am
by Little John
netmaestro wrote:That's what syntax errors are for. This should raise one imho
Exactly. It would help us to avoid bugs in our programs, which is important.
idle wrote:it would be handy if it worked like it does in c
No, please! ;-)

I think

Code: Select all

a = b = c
either should assign #True or #False to 'a' (depending on whether or not 'b' equals 'c') -- IMHO this is the expected behaviour in a BASIC flavor.
Or, if this is not wanted, it should raise a syntax error.
Since C is not an example for a language with good readable syntax, things like this IMHO shouldn't be introduced into PureBasic.

Regards, Little John

Re: Should this work?

Posted: Wed Oct 21, 2009 12:54 pm
by Kaeru Gaman
netmaestro wrote:That's what syntax errors are for. This should raise one imho, which is my whole (and only) point.
yes you're right. I thought about it awhile...
it could be a typo and you would be screwed if it hides in 30K lines of code.
Little John wrote:... should assign #True or #False to 'a' (depending on whether or not 'b' equals 'c') -- IMHO this is the expected behaviour in a BASIC flavor.
in most BASIC dialects, the Boolean Expression has to be in brackets to be evaluated correctly.
the sole double eval "a=b=c" would raise an error in almost every environment.

Re: Should this work?

Posted: Wed Oct 21, 2009 1:21 pm
by Little John
Kaeru Gaman wrote:in most BASIC dialects, the Boolean Expression has to be in brackets to be evaluated correctly.
the sole double eval "a=b=c" would raise an error in almost every environment.
I agree. Forcing the programmer to write b=c into brackets if s/he wants it to be treated as Boolean expression makes things clearer.

However, is a=b=c really a double evaluation? E.g. idle wants this to be a double assignment. ;-)
IMHO part of the confusion in this situation derives from the fact, that in BASIC '=' is used as relational operator and as assignment operator as well.

Regards, Little John

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! :shock:

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! :shock:

Boolean Expressions in PureBasic?
Oct.21st now is a Historic Date.
That goes double for me! :D

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. 8)
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. :D
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! :D
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.