Just starting out? Need help? Post your questions and find answers here.
netmaestro
PureBasic Bullfrog
Posts: 8451 Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada
Post
by netmaestro » Sun Oct 18, 2009 12:09 am
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
dhouston
Enthusiast
Posts: 430 Joined: Tue Aug 21, 2007 2:44 pm
Location: USA (Cincinnati)
Contact:
Post
by dhouston » Sun Oct 18, 2009 12:57 am
Try it with B=10, then A=10 (only one at a time).
Demivec
Addict
Posts: 4260 Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA
Post
by Demivec » Sun Oct 18, 2009 1:30 am
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.
Rook Zimbabwe
Addict
Posts: 4322 Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:
Post
by Rook Zimbabwe » Sun Oct 18, 2009 3:11 am
I get a debug output of:
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.
blueznl
PureBasic Expert
Posts: 6166 Joined: Sat May 17, 2003 11:31 am
Contact:
Post
by blueznl » Sun Oct 18, 2009 9:42 am
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 ... )
Olliv
Enthusiast
Posts: 542 Joined: Tue Sep 22, 2009 10:41 pm
Post
by Olliv » Sun Oct 18, 2009 5:15 pm
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
Posts: 3415 Joined: Sat Jun 30, 2007 8:04 pm
Post
by Mistrel » Sun Oct 18, 2009 10:04 pm
The problem here is that PureBasic uses '=' for both assignment and comparison. This obscure syntax can only lead to unexpected behavior.
blueznl
PureBasic Expert
Posts: 6166 Joined: Sat May 17, 2003 11:31 am
Contact:
Post
by blueznl » Sun Oct 18, 2009 10:52 pm
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 ... )
Kaeru Gaman
Addict
Posts: 4826 Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany
Post
by Kaeru Gaman » Mon Oct 19, 2009 1:03 am
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.
netmaestro
PureBasic Bullfrog
Posts: 8451 Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada
Post
by netmaestro » Mon Oct 19, 2009 1:07 am
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
Olliv
Enthusiast
Posts: 542 Joined: Tue Sep 22, 2009 10:41 pm
Post
by Olliv » Mon Oct 19, 2009 3:39 am
@Kaeru
What does "bull" mean?
Ollivier
citystate
Enthusiast
Posts: 638 Joined: Sun Feb 12, 2006 10:06 pm
Post
by citystate » Mon Oct 19, 2009 7:14 am
@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
Posts: 7581 Joined: Fri Apr 25, 2003 5:24 pm
Post
by PB » Mon Oct 19, 2009 9:29 am
> when you write such bull it's your own fault
, netmaestro will kick you in the nuts for that!
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
idle
Always Here
Posts: 5836 Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand
Post
by idle » Mon Oct 19, 2009 10:16 am
yes it should raise a syntax error but it would be handy if it worked like it does in c.
dhouston
Enthusiast
Posts: 430 Joined: Tue Aug 21, 2007 2:44 pm
Location: USA (Cincinnati)
Contact:
Post
by dhouston » Mon Oct 19, 2009 11:11 am
I agree that it should raise an error when compiled. I posted about a similar problem some time ago.