BigEd wrote:
Nearby, Garth mentions the "language extension" packs for the Basic on HP's handheld computer.
So, I wondered: what language extensions might people want in a Basic?
People have often added extensions to the MS Basics via the USR statements, as well as CALL, (Applesoft also has an '&' operator to do the same thing), so there is always that - the question is what extensions... Things like graphics and sound are very platform dependant but language constructs like while/until, switch, multi-line if/then/else really require big changes to the interpreter core itself.
Having written my own Basic, I've got a pretty good idea of what
I wanted, but my Basic currently is written in C and needs a modern Unix-like OS as a host platform. I do feel that writing (or re-writing) a BASIC will never please everyone...
Back in the 8-bit world.... I think it's hard to beat BBC Basic for an
interpreted BASIC. 32-bit integers, 40-bit floats, named procedures and functions with local variables supporting recursion. Built-in multi-pass assembler, file handling, sound and graphics. It is true to say that while the language supports various things, it does require an underlying operating system to do the donkey work (e.g. sound and the physical interface to the filing system), however it's almost all there and fits inside a 16KB ROM. It's also the fastest 8-bit Basic that I know of - almost twice the speed of an MS Basic on the same hardware, but the boffins at Acorn were Cambridge computer science graduates and had the benefit of writing it in 1980 (with prior experience of Acorn Atom Basic), some years after the MS Basics in the Apple, PET, etc. and didn't have the space (= cost) concerns of early 8 or 12KB ROMS of the early micros.
The original 8-bit BBC Basic lacks SWITCH, but it's always been there via ON x GOTO ... (it's crude, but it's BASIC)
And the bit about the OS doing some of the donkey-work is a good one to note - (or I'd like to think so) - while BBC Basic has sound, graphics and file commands built-in, it calls the underlying operating system to actually execute them, so I'd like to think that anyone writing a new 8-bit BASIC might do similar via simple set of "system calls" (The Beeb, Apple, PET and I'm sure some others) all have fixed address entry points into the underlying monitor or OS so look at doing the same? I did the bare minimum to get BBC Basic going on my Ruby6502 board, and once it was going, I deleted what was a Wozmon look-a-like and implemented an Acorn MOS look-a-alike and most other (Acorn) system calls which indirectly also enabled me to run other BBC Micro application ROMs, so keeping a common interface would be nice to help porting to other platforms. (My OS is now just under 12KB, but it's very verbose with text error messages and I've made no attempt to code for size)
BBC Basic isn't perfect and it has things that irritate me - spaces can sometimes be problematic, but that's the limitations of squeezing it into the available ROM space.
Other more modern constructs? objects/structures? I'm not sure they need to belong in an 8-bit BASIC. I did add associative arrays into my Basic - more as a challenge from a friend than anything else - a$ ("foo") = "bar" sort of thing - initially to interface to SQLite, but I didn't go that far - which leads to feature creep - when friends, or "the internet" makes a suggestion then puts pressure on you (My Basic doesn't have 'next' but I was persuaded by a very small number of people to put it in, so I did - then they never used it, so I took it out again and decided after that that it was
my basic and not theirs)
And then there is the assembler that the implementer will use - does it run under MS DOS/Windows, Linux, Mac,Apple II, ... ? Does it use assembler specific features, etc. I think it's really hard to make something universal and able to please everyone.
Back to the subject: There are a small number of things that I want in my own Basic that I didn't implement, so these might be handy - one is a string split operator - I was tasked with writing some code to parse a CSV file and having a string split operator would have sped it up a little. Another other is the "classic" matrix operations. I also never bothered with integer variable types because integer arithmetic is not significantly faster than double precision floats on a modern CPU these days. (although it is something I'll add when I re-implement my Basic on my Ruby system) However in the 8-bit world, if you have proper integers, then a MULDIV operator might be useful where interpreted floating point may well be slower than integer arithmetic - so foo% = muldiv (a%, b%, c%) would take a% multiply by b% to produce an un-truncated number internally, then divide by c%. This can make fixed point arithmetic somewhat more flexible and faster.
So with all that in-mind - write the "core" of a modern 8-bit Basic, make it well documented and extensible/customisable by others and use a common interface to the underlying OS. Use a relatively plain old assembler and off you go... (Oh, and make it store programs to some underlying OS/filing system as plain text and not tokenised binary!)
Cheers,
-Gordon