Should this work?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: Should this work?

Post 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.
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Should this work?

Post 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
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 »

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.
oh... and have a nice day.
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Should this work?

Post 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
Fred
Administrator
Administrator
Posts: 18162
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: 4260
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: 4777
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: 18162
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: 4777
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: 3893
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 ?"
A little PureBasic review
Fred
Administrator
Administrator
Posts: 18162
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.
Post Reply