Should this work?

Just starting out? Need help? Post your questions and find answers here.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Should this work?

Post 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.
BERESHEIT
User avatar
dhouston
Enthusiast
Enthusiast
Posts: 430
Joined: Tue Aug 21, 2007 2:44 pm
Location: USA (Cincinnati)
Contact:

Re: Should this work?

Post by dhouston »

Try it with B=10, then A=10 (only one at a time).
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 »

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.
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Re: Should this work?

Post 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:
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Should this work?

Post by blueznl »

It's not allowed. I think it would be great if the compiler would raise an error.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: Should this work?

Post 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
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: Should this work?

Post by Mistrel »

The problem here is that PureBasic uses '=' for both assignment and comparison. This obscure syntax can only lead to unexpected behavior.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Should this work?

Post 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.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
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 »

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.
oh... and have a nice day.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Should this work?

Post 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.
BERESHEIT
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: Should this work?

Post by Olliv »

@Kaeru

What does "bull" mean?

Ollivier
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

Re: Should this work?

Post by citystate »

@Olliv: "Bull" is synonymous with "crap". It's derived from "Bullsh*t", but is considered a tamer term
there is no sig, only zuul (and the following disclaimer)

WARNING: may be talking out of his hat
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Should this work?

Post by PB »

> when you write such bull it's your own fault

:lol:, netmaestro will kick you in the nuts for that! :D
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Should this work?

Post by idle »

yes it should raise a syntax error but it would be handy if it worked like it does in c.
User avatar
dhouston
Enthusiast
Enthusiast
Posts: 430
Joined: Tue Aug 21, 2007 2:44 pm
Location: USA (Cincinnati)
Contact:

Re: Should this work?

Post by dhouston »

I agree that it should raise an error when compiled. I posted about a similar problem some time ago.
Post Reply