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.
Suggestion: Do/Loop/While/Until/exit
Re: Suggestion: Do/Loop/While/Until/exit
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.
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
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
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.
In other words, totally doable, but maybe better suited to one of the IDEs that's baked into the ROM.
- ahenry3068
- Posts: 1144
- Joined: Tue Apr 04, 2023 9:57 pm
Re: Suggestion: Do/Loop/While/Until/exit
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
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.
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
Nice! That is very flexible!ahenry3068 wrote: ↑Fri Apr 19, 2024 7:13 amFUNCTION 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$
- ahenry3068
- Posts: 1144
- Joined: Tue Apr 04, 2023 9:57 pm
Re: Suggestion: Do/Loop/While/Until/exit
This is pretty much the approach I'm taking manually to translate some Qbasic code to BASLOAD where the QBASIC code usesmgkaiser wrote: ↑Sat Apr 20, 2024 12:43 amNice! That is very flexible!ahenry3068 wrote: ↑Fri Apr 19, 2024 7:13 amFUNCTION 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$
FUNCTION END FUNCTION