Page 1 of 2

BASIC: New Commands

Posted: Fri Aug 28, 2020 1:41 am
by geek504

LOCATE (GW-BASIC) or HTAB and VTAB (Applesoft BASIC)

MOD (modulo)

ELSE (would be nice)

 


BASIC: New Commands

Posted: Fri Aug 28, 2020 5:10 am
by StephenHorn

I have a feeling that "ELSE" would be the hardest one out of that lot. XD


BASIC: New Commands

Posted: Fri Aug 28, 2020 5:30 am
by TomXP411

Yes, I would really, really like to see LOCATE. 



ELSE isn't that hard... Commodore did it on the 128. ELSE has to be on the same line as the IF/THEN. So the parser just skips forward in the line when the IF is false and looks for an ELSE.

The problem is that this makes IF/THEN slower, since the parser has to work through the whole line when the condition is false. And it's very easy to reverse the IF condition and GOTO over a block of code, so I'm not sure ELSE is actually necessary or useful. 

But LOCATE and MOD are definitely useful. MOD makes certain type of math much faster (especially when doing byte conversions and base conversions), and LOCATE really should have been part of the command set since the beginning. 

 


BASIC: New Commands

Posted: Fri Aug 28, 2020 5:34 am
by TomXP411


3 hours ago, geek504 said:




LOCATE (GW-BASIC) or HTAB and VTAB (Applesoft BASIC)



MOD (modulo)



ELSE (would be nice)



 



Add these as feature requests, here:

https://github.com/commanderx16/x16-rom/issues

LOCATE is actually already on the list: https://github.com/commanderx16/x16-rom/issues/128

ELSE and MOD are not yet there, so adding those as suggestions might be nice.

Create a separate issue for each of the two commands and prefix the title with "Feature Request." So:


  • Feature Request: ELSE statement


  • Feature Request: MOD operator


 


BASIC: New Commands

Posted: Fri Aug 28, 2020 5:45 am
by BruceMcF


4 hours ago, geek504 said:




LOCATE (GW-BASIC) or HTAB and VTAB (Applesoft BASIC)



MOD (modulo)



ELSE (would be nice)



 



ELSE could be a matter of someone integrating the 128 code into the current Basic and doing a pull request.

LOCATE ... AT-XY in Forth ... with just the first two parameters is just making a Kernel call available.The third option to turn off the cursor for "silent" placement of text graphics is also valuable, especially since that was done in the C64 with magic locations.

For GET-XY, CURSOR(0|1) where 0 is the X and 1 is the Y would work.

Note: ELSE is in the feature requests, just a lot further back.


BASIC: New Commands

Posted: Fri Aug 28, 2020 11:58 am
by SerErris

I agree, I do not see any reason for else.

You do not need to do anything it works out of the box like that:


Quote




 



10 A=0

20 IF A>0 THEN PRINT "SOMETHING":A=0:GOTO100

30 REM ELSE

40 PRINT "SOMETHING ELSE"

50 A=1

100 REM CONTINUE

110 PRINT "WE LEFT"



 



So we even have a ELSE with multiple lines already in it. Yes it is a little bit different to write but it is not an issue and easy to understand after you  worked with it. 


BASIC: New Commands

Posted: Fri Aug 28, 2020 2:54 pm
by geek504


9 hours ago, TomXP411 said:




Feature Request: MOD operator



Done!


BASIC: New Commands

Posted: Fri Aug 28, 2020 3:00 pm
by geek504


3 hours ago, SerErris said:




So we even have a ELSE with multiple lines already in it. Yes it is a little bit different to write but it is not an issue and easy to understand after you  worked with it.



Agreed. ELSE would be nice but not essential since it can be done using IF/THEN/GOTO. It's actually better not to have it for two reasons:

1. Use less ROM space; BUT if we have 128-512K ROM, why not?

2. Easier transition to assembly language programming which is really COMPARE/BRANCH/JUMP style.

I only suggested for the sole purpose of teaching kids how to program and ELSE would be nice to have! Two-character variable names is tough to teach with... I'm thinking for teaching just programming maybe GW-BASIC is better, but if I wanted to teach hardware too, moving from GW-BASIC to C64 BASIC would be quite "painful"!


BASIC: New Commands

Posted: Fri Aug 28, 2020 9:57 pm
by SerErris

Maybe it is good to start very basic and work your way up. The same is true for if then else. It is either else or goto, does not matter. Most languages do not have a goto instruction. The problem is that else is very slow the goto variant is also much faster which is most likely not a concern. Easier to read for someone not that familiar with a simple basic or even assembler dialect, so maybe it is good to implement and have options, however even the C128 implementation is very limited (one line if instruction)


BASIC: New Commands

Posted: Fri Aug 28, 2020 11:29 pm
by TomXP411


1 hour ago, SerErris said:




Most languages do not have a goto instruction.



Quite the opposite is true... while modern, fad languages tend to leave it out (Python is a notable example), the keyword and operation is in most programming languages. C, C++, and C# all have it, for example, and Microsoft gives a pretty compelling use case in the c# documentation. 

In fact, out of the current languages labeled as most popular, 7 of them have explicit GOTO statements. And as you go back in time, it gets difficult to find a language without an unconditional branch statement before Java. (There was one, "BLISS", but I don't think anyone has heard of it outside of academic circles.)