QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: Pete on February 28, 2019, 01:10:45 pm

Title: Riddle me this...
Post by: Pete on February 28, 2019, 01:10:45 pm
a$ = "0": b$ = "5"

PRINT a$ < b$

Result: -1, which is all well and good, but why won't QB64 accept it this way?

PRINT "0" < "5"

Pete ^^0^^
Title: Re: Riddle me this...
Post by: Gets on February 28, 2019, 01:25:13 pm
what's being compared in a$ < b$ ? It looks ordinary since you're using numbers, but you could also compare "dog" and "cat" the same way.


Title: Re: Riddle me this...
Post by: Pete on February 28, 2019, 01:32:23 pm
Nope, that's not it, because...

a$ = "dog": b$ = "cat"
PRINT a$ > b$
END

Result is -1, true, because strings are evaluated alphabetically, and d > c.

Pete
Title: Re: Riddle me this...
Post by: FellippeHeitor on February 28, 2019, 01:33:29 pm
Code: QB64: [Select]
  1. PRINT ("0") < ("5")

That works, just don't ask me why. Parsing is a bitch and I have utmost respect for what Galleon did.

Riddle me this: did that work in QB4.5? Then we'll have to work around it.
Title: Re: Riddle me this...
Post by: Pete on February 28, 2019, 01:59:26 pm
I would appreciate it if someone with DOSBox QuickBASIC could check this out. I have one on my retired Win 7. If nobody posts soon, I'll try and fire it up, but no promises if it still will boot.

Fell, neat find on adding the parentheses! I did not know that was available.

Pete
Title: Re: Riddle me this...
Post by: Cobalt on February 28, 2019, 02:49:26 pm
QB45 ,through DOSBOX, is green across the board.
show -1 for each item
PRINT a$ < b$
PRINT "0" < "5"
and
PRINT ("0") < ("5")
Title: Re: Riddle me this...
Post by: Pete on February 28, 2019, 02:58:41 pm
Thanks for checking that.

Fell, drop everything you're doing right now, put you kid up for adoption, and get busy on this incompatibility immediately. Either that or take the family out for dinner and realize that no one else will ever stumble upon this WHOGAS inconsistency... or just let fluckin' luke take care of it. Forget Steve, he's on the clock already.

Pete :D
Title: Re: Riddle me this...
Post by: TempodiBasic on February 28, 2019, 03:48:19 pm
Hi
but it seems that Parser doesn't like  comparing costant string value!

see this  [ This attachment cannot be displayed inline in 'Print Page' view ]  
  [ This attachment cannot be displayed inline in 'Print Page' view ]  

but the issue is in the PRINT or in the < operator?
Title: Re: Riddle me this...
Post by: FellippeHeitor on February 28, 2019, 04:10:37 pm
PRINT is a special case for QB64 and as such it is processed internally differently. If you use literal string comparison in an IF statement, for example, it'll work.

Code: QB64: [Select]
  1. IF "0" < "5" THEN
  2.     PRINT "duh!"
Title: Re: Riddle me this...
Post by: victorhugo on February 28, 2019, 05:06:57 pm
in SDL works correctly
Title: Re: Riddle me this...
Post by: SMcNeill on February 28, 2019, 05:21:25 pm
in SDL works correctly

I would imagine this broke when auto-semicolon was added into PRINT.

In SDL, try:  PRINT “0”x”5”

You get an error...

In GL, PRINT “0”x”5” automatically adds semicolons to make that statement PRINT “0”; x; “5”.

I’d imagine (but can’t be 100% certain) that the insert semi-colon addition is what’s causing the discrepancy between the SDL and GL version.  Comparing the translated c-output in main.txt would probably verify the issue.
Title: Re: Riddle me this...
Post by: victorhugo on February 28, 2019, 05:45:43 pm
It is probable, but anyway SDL is still more consistent with the old versions created for DOS
Title: Re: Riddle me this...
Post by: SMcNeill on February 28, 2019, 05:59:35 pm
It is probable, but anyway SDL is still more consistent with the old versions created for DOS

Depends on what you’re comparing.  QB45 added semicolons between PRINT statements automatically; our SDL version didn’t.  It’s a trade of one incompatibility for another, with the only real difference being the GL version is being maintained and can be corrected, whereas the SDL version won’t be.  ;)