Page 1 of 3

Should this work?

Posted: Sun Oct 18, 2009 12:09 am
by netmaestro

Code: Select all

c=10
a=b=c
Debug a
Debug b
Debug c
Shouldn't it be a syntax error? Actually it would be a cool feature if it set all members at once to the same value.

Re: Should this work?

Posted: Sun Oct 18, 2009 12:57 am
by dhouston
Try it with B=10, then A=10 (only one at a time).

Re: Should this work?

Posted: Sun Oct 18, 2009 1:30 am
by Demivec
netmaestro wrote:

Code: Select all

c=10
a=b=c
Debug a
Debug b
Debug c
Shouldn't it be a syntax error? Actually it would be a cool feature if it set all members at once to the same value.
It would be great if it did work, but it only does work if you are lucky.

This doesn't generate a syntax error and often leads to confusion regarding whether boolean expressions are legal or not when used in assigning a value. The assignment can also be seen as "a = (b = c)".

I think as it stands currently it should be changed so that it does raise a syntax error.

Re: Should this work?

Posted: Sun Oct 18, 2009 3:11 am
by Rook Zimbabwe
I get a debug output of:

Code: Select all

10
0
10
Which kind of makes sense given the expression a=b=c where we are supposing a=b equals c so a=0, b=0 and c=10 therefore a=10

{{EDIT: After rereading Jared's post I said something like he sadi but much worse in explanation!!! }}

but if I was assigning variables I would assign like that anyway... especially if I wanted b=10 as well. :mrgreen:

Re: Should this work?

Posted: Sun Oct 18, 2009 9:42 am
by blueznl
It's not allowed. I think it would be great if the compiler would raise an error.

Re: Should this work?

Posted: Sun Oct 18, 2009 5:15 pm
by Olliv
I would suggest however this function works fine but for this following operation (just considering "Or 0" or "And 1" is implicit):

Code: Select all

Dim Answer$(1)
Answer$(0) = "False"
Answer$(1) = "True"
For b = -1 To 1
    For c = -1 To 1

        a=((b=c) Or 0)

        Debug Str(b) + " equal " + Str(c) + " ? >> " + answer$(a)
    Next
Next

Re: Should this work?

Posted: Sun Oct 18, 2009 10:04 pm
by Mistrel
The problem here is that PureBasic uses '=' for both assignment and comparison. This obscure syntax can only lead to unexpected behavior.

Re: Should this work?

Posted: Sun Oct 18, 2009 10:52 pm
by blueznl
Everything we say on a = ( b = c ) is irrelevant. It's simply not allowed. If it works, good for you, but no guarantee that it will.

Re: Should this work?

Posted: Mon Oct 19, 2009 1:03 am
by Kaeru Gaman
it's not supported and not reliable, this is right... but it works exactly as expected.

in PB Boolean Expressions are not supported, the term (b=c) will not return true or false, but the second value. I often seen that.
(b=c) returns 10, this is assigned to a.

I don't care if this should raise an error, in the end when you write such bull it's your own fault.

Re: Should this work?

Posted: Mon Oct 19, 2009 1:07 am
by netmaestro
in the end when you write such bull it's your own fault
That's what syntax errors are for. This should raise one imho, which is my whole (and only) point. Much of the discussion in this thread is OT.

Re: Should this work?

Posted: Mon Oct 19, 2009 3:39 am
by Olliv
@Kaeru

What does "bull" mean?

Ollivier

Re: Should this work?

Posted: Mon Oct 19, 2009 7:14 am
by citystate
@Olliv: "Bull" is synonymous with "crap". It's derived from "Bullsh*t", but is considered a tamer term

Re: Should this work?

Posted: Mon Oct 19, 2009 9:29 am
by PB
> when you write such bull it's your own fault

:lol:, netmaestro will kick you in the nuts for that! :D

Re: Should this work?

Posted: Mon Oct 19, 2009 10:16 am
by idle
yes it should raise a syntax error but it would be handy if it worked like it does in c.

Re: Should this work?

Posted: Mon Oct 19, 2009 11:11 am
by dhouston
I agree that it should raise an error when compiled. I posted about a similar problem some time ago.