Page 1 of 1
Suggestion: Do/Loop/While/Until/exit
Posted: Thu Apr 18, 2024 8:55 pm
by Desert-Fox
I hope this hasn't been brought up previously. I looked but could not find anything.
Would it be possible to add DO/LOOP/WHILE/UNTIL/EXIT to the current BASIC for the X16?
I had it in BASIC 7.0 on the C128 and was hoping it might be included here.
Re: Suggestion: Do/Loop/While/Until/exit
Posted: Thu Apr 18, 2024 9:13 pm
by TomXP411
Honestly, I think the team is done adding new BASIC commands. While DO loops are handy, they don't actually add functionality that can't be achieved with an IF/GOTO.
We've had some discussion on the Discord, and I've even started working on a P-Code engine, but then David dropped the 65C816 and "look! A serial card!" bombs on us, and we all kind of pivoted to that.
At some point, there will be a BASIC compiler, and that's where new language features will be added.
In the meantime, it's fairly straightforward to convert DO and WHILE loops to IF/GOTO loops:
Here's a WHILE loop in line numbered BASIC:
100 WHILE condition
110 do stuff
120 do more stuff
130 LOOP
Here's the IF/GOTO version:
100 GOTO 130
110 do stuff
120 do more stuff
130 IF condition GOTO 110
and the BASLOAD version:
GOTO L2
L1:
do stuff
do more stuff
L2:
IF condition THEN L1
To convert a DO loop, just leave out the first GOTO. Otherwise, it's the same.
Re: Suggestion: Do/Loop/While/Until/exit
Posted: Fri Apr 19, 2024 2:49 am
by mgkaiser
Maybe add them to BASLOAD and let it implement them with existing BASIC 2.0 commands. Other "syntactic sugar" like SELECT CASE and multi line IF...THEN could also be implemented. Maybe even SUB and FUNCTION? Yes, FUNCTION is a stretch...
Re: Suggestion: Do/Loop/While/Until/exit
Posted: Fri Apr 19, 2024 3:04 am
by DragWx
This sounds like BASIC++, like what C++ is to C.
In other words, totally doable, but maybe better suited to one of the IDEs that's baked into the ROM.
Re: Suggestion: Do/Loop/While/Until/exit
Posted: Fri Apr 19, 2024 7:13 am
by ahenry3068
mgkaiser wrote: ↑Fri Apr 19, 2024 2:49 am
Maybe add them to BASLOAD and let it implement them with existing BASIC 2.0 commands. Other "syntactic sugar" like SELECT CASE and multi line IF...THEN could also be implemented. Maybe even SUB and FUNCTION? Yes, FUNCTION is a stretch...
FUNCTION Might be easier than SELECT CASE. If it was me, Function would translate as so.
Create a New Var with the same Name as FUNCTION
FUNCTION FirstLetter(X$):
FirstLetter=LEFT(X$,1)
RETURN
B=FirstLetter("Hello")
Translates to:
FirstLetterP1$="Hello"
GOSUB Function
FirstLetter:
B=LEFT$(FirstLetterP1$,1)
RETURN
FirstLetterP1$="Hello"
GOSUB FirstLetter
B=FirstLetter$
Re: Suggestion: Do/Loop/While/Until/exit
Posted: Fri Apr 19, 2024 3:20 pm
by BruceRMcF
The real benefits of having them in RomBASIC is that they can be made to be more efficient, like FOR / NEXT, because you can stack information on a structure stack to be completed by the end of the structure and avoid scanning through the program for the target line as with GOTO.
But BASLOAD implenting structures with IF/THEN and GOTO and then providing a Blitz-style p-code compiler for the RomBASIC code provides that benefit at the point of doing the p-code compilation, which substantially reduces the benefit of adding it to RomBASIC.
This is similar to the discussions from a couple of years back of adding integer arithmetic to expressions which are presently converting integers to floats for evaluation and then converting back to integers ... the real bang for the buck in that upgrade is not in RomBASIC, it's adding that as a refinement to the Blitz compiler.
Re: Suggestion: Do/Loop/While/Until/exit
Posted: Sat Apr 20, 2024 12:43 am
by mgkaiser
ahenry3068 wrote: ↑Fri Apr 19, 2024 7:13 am
mgkaiser wrote: ↑Fri Apr 19, 2024 2:49 am
Maybe add them to BASLOAD and let it implement them with existing BASIC 2.0 commands. Other "syntactic sugar" like SELECT CASE and multi line IF...THEN could also be implemented. Maybe even SUB and FUNCTION? Yes, FUNCTION is a stretch...
FUNCTION Might be easier than SELECT CASE. If it was me, Function would translate as so.
Create a New Var with the same Name as FUNCTION
FUNCTION FirstLetter(X$):
FirstLetter=LEFT(X$,1)
RETURN
B=FirstLetter("Hello")
Translates to:
FirstLetterP1$="Hello"
GOSUB Function
FirstLetter:
B=LEFT$(FirstLetterP1$,1)
RETURN
FirstLetterP1$="Hello"
GOSUB FirstLetter
B=FirstLetter$
Nice! That is very flexible!
Re: Suggestion: Do/Loop/While/Until/exit
Posted: Sun Apr 21, 2024 12:27 am
by ahenry3068
mgkaiser wrote: ↑Sat Apr 20, 2024 12:43 am
ahenry3068 wrote: ↑Fri Apr 19, 2024 7:13 am
mgkaiser wrote: ↑Fri Apr 19, 2024 2:49 am
Maybe add them to BASLOAD and let it implement them with existing BASIC 2.0 commands. Other "syntactic sugar" like SELECT CASE and multi line IF...THEN could also be implemented. Maybe even SUB and FUNCTION? Yes, FUNCTION is a stretch...
FUNCTION Might be easier than SELECT CASE. If it was me, Function would translate as so.
Create a New Var with the same Name as FUNCTION
FUNCTION FirstLetter(X$):
FirstLetter=LEFT(X$,1)
RETURN
B=FirstLetter("Hello")
Translates to:
FirstLetterP1$="Hello"
GOSUB Function
FirstLetter:
B=LEFT$(FirstLetterP1$,1)
RETURN
FirstLetterP1$="Hello"
GOSUB FirstLetter
B=FirstLetter$
Nice! That is very flexible!
This is pretty much the approach I'm taking manually to translate some Qbasic code to BASLOAD where the QBASIC code uses
FUNCTION
END FUNCTION