Author Topic: Riddle me this...  (Read 3104 times)

0 Members and 1 Guest are viewing this topic.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Riddle me this...
« 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^^
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Gets

  • Newbie
  • Posts: 28
    • View Profile
Re: Riddle me this...
« Reply #1 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.



Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Riddle me this...
« Reply #2 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

FellippeHeitor

  • Guest
Re: Riddle me this...
« Reply #3 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.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Riddle me this...
« Reply #4 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Riddle me this...
« Reply #5 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")
Granted after becoming radioactive I only have a half-life!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Riddle me this...
« Reply #6 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Riddle me this...
« Reply #7 on: February 28, 2019, 03:48:19 pm »
Hi
but it seems that Parser doesn't like  comparing costant string value!

see this  [ You are not allowed to view this attachment ]  
  [ You are not allowed to view this attachment ]  

but the issue is in the PRINT or in the < operator?
« Last Edit: February 28, 2019, 03:49:21 pm by TempodiBasic »
Programming isn't difficult, only it's  consuming time and coffee

FellippeHeitor

  • Guest
Re: Riddle me this...
« Reply #8 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!"

Offline victorhugo

  • Newbie
  • Posts: 2
  • Since 1985 with BASIC in a TIPC and counting ...
    • View Profile
Re: Riddle me this...
« Reply #9 on: February 28, 2019, 05:06:57 pm »
in SDL works correctly

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Riddle me this...
« Reply #10 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.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline victorhugo

  • Newbie
  • Posts: 2
  • Since 1985 with BASIC in a TIPC and counting ...
    • View Profile
Re: Riddle me this...
« Reply #11 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

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Riddle me this...
« Reply #12 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.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!