So I was reading the old ZX81 manual last night (bringing back fond memories since that is how I learned BASIC). I either missed it or forgot about it but it allows variable names with spaces in it:
Code: Select all
let a b c = 10
print a b c
print abc
Hmmm...don't really like that. Easy (but annoying) to implement as you basically just skip spaces and store the variable as a traditional one. Still, weird implementation.
Oh, and as for the special character set of the zxtools variety...grrr that they added \" which creates a pain of a case in my code. I'd rather they used a 3rd special character instead since the way I tried to be efficient in code is to always look for 2 characters following a \ and only one following a % when using cursor keys. I may change it to \"" internally (and the ZX81 shows it as "" on the keyboard) and convert it to-and-from when reading and writing files since that may add the least code.
This is a function to figure out how many ZX81 characters I have as an example (using my 90's coding style):
Code: Select all
len = 0;
for (i=0; lstr[i]!='\0'; i++)
{ switch(lstr[i]) { case '\\': i++; case '%': i++; default: len++; } }
BTW, here is another beauty. If my students ever saw this they'd frown since I spend a good amount of time teaching good programming techniques. But I'm trying to save bytes to not have the executable grow too fast. Here I'm avoiding additional assignments since a goto is cheaper. I will revisit this to see if I can do it more properly. Maybe use a strcp function instead but that may add a speed tradeoff which is ok in non-critical code. This code tries to figure out how many spaces to add before line numbers so they all align when LISTing the code:
Code: Select all
if (j == 0) /* start of a new line of BASIC */
{
if (fstr[i+1] == ' ')
{ lstr[j++] = ' '; goto in2; } /* reduce code to indent 3 */
else if (fstr[i+2] == ' ')
{ in2: lstr[j++] = ' '; goto in3; } /* reduce code to indent 2 */
else if (fstr[i+3] == ' ')
{ in3: lstr[j++] = ' '; }
}
As I told Norm, there are things in the code I like but there are many things I don't. I was much younger when I wrote this and one of the principles I'm applying is one that I've taught my students which is, when working in a foreign code-base (and after almost 30 years this sure feels foreign) try and abide by existing conventions instead of creating a mess and doing your own thing. So today I don't do some of the formatting I did in the 90's, etc, but am sticking with it. Plus, 3 space indents...ugh...I keep it as 4 now mostly.