Should this work?
Re: Should this work?
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.
Logically, 'a = b = c = d' creates a syntax error at my compiler. So, there is certainly a little bug to solve in the compiler.
-
- Addict
- Posts: 4777
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Should this work?
Exactly. It would help us to avoid bugs in our programs, which is important.netmaestro wrote:That's what syntax errors are for. This should raise one imho
No, please!idle wrote:it would be handy if it worked like it does in c

I think
Code: Select all
a = b = c
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
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: Should this work?
yes you're right. I thought about it awhile...netmaestro wrote:That's what syntax errors are for. This should raise one imho, which is my whole (and only) point.
it could be a typo and you would be screwed if it hides in 30K lines of code.
in most BASIC dialects, the Boolean Expression has to be in brackets to be evaluated correctly.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.
the sole double eval "a=b=c" would raise an error in almost every environment.
oh... and have a nice day.
-
- Addict
- Posts: 4777
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Should this work?
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.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.
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?
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:
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.
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: Should this work?
!WOW! 
Boolean Expressions in PureBasic?
Oct.21st now is a Historic Date.

Boolean Expressions in PureBasic?
Oct.21st now is a Historic Date.
oh... and have a nice day.
Re: Should this work?
That goes double for me!Kaeru Gaman wrote:!WOW!
Boolean Expressions in PureBasic?
Oct.21st now is a Historic Date.

-
- Addict
- Posts: 4777
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Should this work?
Very cool.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.

Thanks in advance!
Regards, Little John
Re: Should this work?
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?
Fred, you give us so much already, we should NEVER whineFred wrote:. . . so don't whine if it doesn't make it for 4.50

cheers
-
- Addict
- Posts: 4777
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Should this work?
I think we can already now take advantage of a macro for this purpose, which can have the same name.
The macro does no error checking, but it can help us in the following respects:
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
- 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.
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: Should this work?
I just stumbled over this:
because, Boolean Expressions are really useful to work with variables...
if it will be a compiler directive, does this mean it will be evaluated at compiletime and can only compare constants?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.
because, Boolean Expressions are really useful to work with variables...
oh... and have a nice day.
Re: Should this work?
You could say we're floating on air.Demivec wrote:That goes double for me!

Re: Should this work?
Yes, this is unclear to me to. How could be a compiler directive ? To me EnableExplicit is a compiler directive.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...
BTW: I'm using a BOOL() macro in just the same way in my code

"Have you tried turning it off and on again ?"
A little PureBasic review
A little PureBasic review
Re: Should this work?
It's a compiler directive which will add the needed ops to returns a boolean values. It will indeed work with any expressions.