Over on the CoCo Facebook group, in a discussion about “why is I always used for loops”, Rob R. left a comment that caught my interest:
“… I have a vague memory that (at least on the Mod I) there were one or two letters that weren’t usable since they could be tokenized to a command. At least some two letter variables would be verboten, like ‘TO.'”
– Rob R. on Facebook
This made me wonder: how many are there? Here are the ones that I think would be problematic:
- AS – in Disk BASIC, there is an “AS” keyword used for the file system. “FIELD #1, 10 AS A$”
- FN – as in “DEF FNA(B)=B*42”
- IF – as in “IF A=1”
- ON – as in “ON X GOTO/GOSUB” or on the CoCo 3, “ON BRK GOTO” or “ON ERR GOTO”
- OR – as in “IF A=1 OR A=2”
- TO – as in “FOR I=1 TO 10”
Using any of these such as “TO=1” or “FN=3” will create a ?SN ERROR.
Are there others?
Also, some of these will work in Color BASIC that will not work if you have Extended or Disk BASIC:
- “DEF FN” was added in Extended, so on a Color BASIC machine you should be able to use FN as a variable.
- “AS” was added in Disk BASIC, so you should be able to use AS on Color and Extended BASIC.
I wonder how many folks wrote BASIC programs using variables that were not allowed when they later added the Extended BASIC ROM and/or Disk BASIC, and wondered why they stopped working?
Until next time…
It wasn’t just two-letter tokenizable combos. Remember that the Color Computer’s BASIC allowed the “use” of variables longer than two characters, by ignoring the part of the variable after the second character. So you also couldn’t use TODAY=3. But it also meant that while you could, for example, use CO=3 you could not use COST=3.
This is also where adding AS to the forbidden list really hurt, because a lot of useful variables begin with AS and were in use in pre-Disk BASIC programs.
I will have to play with this. I never used longer variable names, and has assumed it just ignored anything after the first two up until an = or whatever, but I suppose the same rules apply when FORA=BTOC won’t work since it didn’t know where the variable name stops and the token begins.
This would “only” hurt when typing in, but not when loading already tokenized programs though?
I’m not that familiar with the CoCo in particular, but I think that most (perhaps all?) implementations of the similar 6502 Microsoft Basic saved program already tokenized.
Btw, did anyone use this as a sort of tamper-protection? I.E. alter the contents in ram to change the name of varibles to “forbidden” names? Say that you enter AX but use a POKE that changes the X to S, then you would be able to have AS as a variable even though you can’t enter it via the editor.
As a bonus: I wonder how modern development environment for vintage computers does this? Don’t know what’s available for the CoCo, but for the Commodore 8-bits IIRC there are two different but somewhat similar modern development environment and I think both can produce tokenized basic programs (in addition to assembler programs). It seems fairly easy to add directives that can temporary disable the tokenization.
Side track: An oddball is the basic in the Atari 8-bit computers. Those store the variable name in the variable area, and the tokenized programs just contain a reference ID to each variable. This means that the amount of variables is limited (IIRC 256 or even less) but on the other hand each use of an existing variable “costs” the same amount of program space no matter the length of the variable name. I bet that you can fiddle with memory content to make the variable names weird in a way that you can’t enter or edit lines that use those variables.
I will have to try the POKE method to see if an altered variable in an already tokenized program would work. It seems like it would. Interesting.
There are several BASIC preprocessors – one by Rick Adams, then there is Super BASIC (Jerry comments here, and has a book in Amazon about it), and then Jason Pittman has one I use. They take nicely formatted source with long names and labels and such, then export it out as a tokenized program or export as ASCII, changing names as needed and such. Interesting concepts, which make all of this irrelevant as long as they know the rules to never use these names. And now I want to test all of them.
That’s an interesting thought! The only other one I can think of is “GO”
Wait, really? Do we get “GO TO” in BASIC as two tokens???
I learned about the two character limit the hard way when I had variables that were only unique in name after the second character overwriting each other. Though I had read the Radio Shack manuals cover to cover, somehow that warning didn’t stick, probably because I was only writing short programs when I first read them.
According to the author of the game ‘Empire’, because the game as initially written in BASIC, even after porting the game to Pascal, he was so familiar with the two character variables that he kept them.