Personal Computer News


SuperBasic

 
Published in Personal Computer News #075

How Super Is The BASIC?

The QL's SuperBasic lives up to its name in some ways, but in others it certainly does not.

First of all the pros. SuperBasic supports a wide range of useful commands that should make programming quite easy and efficient. It has a number of control structures which, though they are not really the standard implementations, do show willingness on Sinclair's part to upgrade Basic to a higher level than is normal.

Control

The control structures are unusual in that they use the command EXIT to get out of them, so instead of:

LET T=0
REPEAT
LET T=T+1
UNTIL T=10

you need to use:

LET T=0
REPEAT loop
LET T=T+1
IF T=10 THEN EXIT loop
END REPeat

The FOR...NEXT is also rather unusual as it is possible to say, for instance:

FOR T=0 TO 10, 7 TO 4 STEP-1,1 TO 4
PRINT T;
NEXT T

and have the routine step T through all the appropriate values and print:

01234567891076541234

Note the QL does not insert leading or trailing spaces as do most other Basics.

Other unusual commands are such things as BAUD, for setting the baud rate of the serial port, full turtle graphics, PAN to scroll the screen horizontally, and SCROLL to do it vertically. It is possible to POKE bytes (8 bits), words (16 bits) and long words (32 bits), renumber a program with RENUM, and do automatic line numbering with AUTO. A SELECT structure is provided which is similar to ON GOTO and SCALE can be used to set the size of a drawing produced by a graphics procedure.

Multiple line procedures, and multiple line functions, with full parameter passing are available and easy to use. One nice thing about the procedures is that they can be defined somewhere at the top of the program and then used as direct commands, so instead of having to type DIR MDV1__ for a directory of drive one, the following procedure can be defined and a directly obtained by typing:

DIR 1
DEF PROCedure DIR (d$)
DIR "MDV" + d$ + "__"
END DEFine

Strings

All the above commands should make SuperBasic something special, but unfortunately there are a few drawbacks.

FILL$("aaaaaa",32767) has a bug in it and is capable of producing very long strings and filling them with rubbish. Typing:

a$=FILL$("aaaaaa",32767)
PRINT LEN(a$)

causes the machine to print garbage.

When the QL is printing a long string, it is not possible to stop the beast with the usual CTRL-SPACE. This applies to any of the commands, such as plotting long lines, and so on. By far the best way of hanging the QL is to press the CTRL, ALT and 7 all at once. No matter what the machine is doing, this will cause it to stop. Of course it is a little difficult to press all these keys at once, but the fact remains that it causes the machine to fall over backwards and go to sleep.

When using FOR...NEXT loops, including anything on the same line as the start of the loop, for example:

FOR T=0 TO 10:PRINT"here"
PRINT T*T
NEXT T

causes 'here' to be printed 11 times and the rest of the loop only once. This applies to placing anything after the colon, even REM.

Functions

Using a recursive function to evaluate factorials such as

DEF FuNction FACT(X)
IF X<1 THEN RETurn 1
RETurn x*FACT(X-1)
END DEFine

and then trying:

PRINT FACT(1000)

will obviously cause an out of memory error, but takes a long time to do it. When it does run out of memory, all the variables are set to zero, making program debugging very difficult, since it is not possible to find out how far the function got before crunching out.

The manual states that RENUM cannot renumber RESTORE. This has now been fixed, as have all the other obvious bugs.

There are still problems with tokenising the Basic commands, and if spaces are into put into the correct positions, e.g. GOTO10, the command will not work but GOTO 10 will.

The date functions are very good and cannot be fooled by trying to feed in bogus dates such as the 32nd of Feb, etc. The problem is that DATE$ cannot be sliced, e.g. PRINT DATE$(1 TO 4) gives an error. To slice it, it is necessary to LET A$=DATE$:PRINT A$(1 TO 4)

The beep command is very difficult to use and in fact the manual says that the best way to find out how it works is to experiment. This is not as easy as it sounds since the documentation is not specific enough as to what the parameters do.

A problem with the Microdrives from Basic is that if the drive is full and a program is saved, the system puts the file name into the directory. Deleting another file to make room and doing a directory makes it appear as if the program has been saved. In practice this file is empty and when loaded back in, the current program is NEWed, possibly causing a total loss.

The SELECT control structure does not work with strings, which is surprising since string equality produces the same result as a numeric equality, i.e. true is 1 and false is 0 (this is not very standard). If this had worked, it would have made SELECT equivalent to CASE, and since REPEAT and a proper FOR and IF structure are included, it seems a shame not to have done things properly.

Usability

Other problems with the Basic are generally caused by its inconsistency and possibly make it a little confusing to the beginner. In some cases, spaces are needed between commands and their arguments, but not in others; similarly, procedures are defined with the arguments in parentheses and then used without them. All this adds up to a fairly confusing system, even for the non-beginner.

It would also have been nice to have had a decent full screen editor, since EDIT line number allows access to only 160 (320 in mode 4) characters of the line at any one time. This may not seem too bad, except that it is possible to have program lines of almost any length.

Verdict

All these problems make the QL's SuperBasic difficult to use at times. A little more error trapping, especially on the string handling, would have been welcome.

If Sinclair can fix all the bugs and make the system a little more usable and improve the keyboard and correct the documentation and... and...

Well, it could be such a good machine with a very good Basic.

Peter Worlock