QL Super Basic

The QL Comes of Age

In the last issue I gave you a brief overview of the hardware angle to Sinclair’s latest computer, the QL. This time, I’ll tell you about some of the features available in this computer’s built-in Super Basic language.

Data Channeling

Like the TS2068 and the Sinclair Spectrum, all input and output is routed through “channels.” The TV display, the keyboard, microdrives, and serial ports are all considered channels. If you hook up additional peripherals, you would define new channels in order to input from or output to them.

By associating these channels with Basic commands, such as, PRINT or INPUT, you can move data and programs from device to device with tremendous ease. Unusual effects can be achieved. For example, you can SAVE to the TV screen, or to the serial port. You can PRINT to the Micro Drives, or INPUT from them.

Besides physical devices, channels can be used to output data to WINDOWS, or sections of the TV screen which act completely independently from any other section of the screen. WINDOWS add an interesting new flavor to the art of programming. They can be used,for instance, to produce many interesting displays. After OPENning a channel to the screen, you use the Basic commands WINDOW, INK, PAPER and BORDER; to define size, location, color and border size of a window. Windows can overlap each other and you can have as many as you want at any given moment.

When PRINTing into a window, you can select different character sizes by using the command CSIZE. The CURSOR command will put the input cursor at the line, column position desired. Once something is printed in a window, you can SCROLL all of it or part of it up or down. Horizontal scrolling (again all or part, left or right) is done using the PAN command.

In addition to Printing to a window, you can also perform all kinds of graphics tricks using CIRCLE (and ellipse), LINE, ARC, and POINT commands. FILL will color objects with a specified ink color.

Programmability

When I first got my QL, sorting out the 140-odd new commands was troublesome. How in the world was I ever going to learn how to use all these new functions? Well, I’m still wrestling with that question, but the more I use this computer, the more I like it.

From a programmer’s standpoint, there are some commands which make the QL a joy to use. AUTO will start the automatic line numbering feature. By attaching two numbers to the Auto command, you can specify the starting line and the increment. Also built-in is RENUM which, as its name implies, renumbers any or all of a program in memory. Add to this extensive micro drive commands: LRUN (load and run) and MRUN (merge and run) are just two of many. Line numbers can range from 1 to 32767, so you should never feel cramped for space.

If you use a monitor with the QL, you can make use of the computer’s Hi-res mode which offers the programmer a particularly nice touch. In this mode the main part of the screen is divided into two separate windows, Program listings will go in one, while output from a program goes in the other. Being able to simultaneously watch a display and view a listing is very handy.

Many of the old familiar Basic commands of the TS1000/2068 are presented in the QL with fancy new capabilities. FOR… NEXT… is a good example. With the old For…. NEXT…. command, you could set up a repeating loop to execute program lines many times. Each time the lines are repeated, the control variable of the FOR…. NEXT…. command would be incremented or decremented. The Super Basic FOR…. NEXT…. does the same thing, but in addition to simple incrementing or decrementing, you can specify the exact value of the control variable. In the QL such a line would look like this:

FOR X=2,4,1,10,5,15 TO 20

Here, each time the loop repeats, the variable X takes on the respective values 2, 4, 1, 10, and 5, then 15, 16, 17, 18, 19, and 20. You can compound a line like this to the extreme:

FOR X=30 to 80 step 3,5,1,11 TO 25,5,10 11,32 TO 0 STEP -1

This loop counts from 30 to 80 by three’s; then it counts by 5 and 1; then 11 to 25 by one’s; then 5, 10 and 11; and finally, it counts backwards from 32 to 0 by one’s. AMAZING!

String & Variable Handling

Remember how other computers’ hackers would put down the ZX/TS machines, because you had to use LET when you defined a variable? Well, the QL doesn’t make you do this anymore. It will accept:

10 A=120
15 B$="hello"

But, that’s not all it can do. Unlike any other version of Basic that I’ve seen, QL Super Basic lets you perform the following:

10 NUMBER=120
20 A$=NUMBER look Ma, no quotes!
30 PRINT A$

The result of these lines is a string variable consisting of three characters. They read “120.” You can further extend this short program with these:

40 PRINT A$+A$
50 NEXT_NUMBER=A$ & A$
60 PRINT NEXT_NUMBER

Line 40 adds 120 and 120 together and prints 240! Line 50 takes “120” and combines it with itself to produce “120120”. This value is then assigned to the numeric variable, NEXT_NUMBER.

All this points to some major differences between Super Basic and ZX/TS Basic. If you try adding two strings using the plus sign, the QL will always try to treat the strings as numbers and add the values together. This is true even if A$=”hello” and B$=”good_bye.” The computer will look for numeric variables called hello and good_bye and try to add them together.

If you want to combine strings you use the ampersand (&):

10 A$="HI "
20 B$="THERE"
30 C$=A$ & B$

This will result in a string variable, C$, which when printed would read HI THERE.

The names that you give variables can be any length up to 255 characters, but you can’t use blank spaces. Instead, you separate words with the underscore. Thus,

LET DAY_OF_THE_WEEK$="Tuesday"

This feature makes writing understandable Basic programs much easier.

Strings are limited to a length of 32K characters. This is restricting, but not constricting. A new command, INSTR, can test the contents of a string for a match to another string. You could say:

10 LET DATA$="Now is the time for all good men..."
20 LET SEARCH$="time"
30 PRINT SEARCH$ INSTR DATA$

The result will be a number (12 in this case) which points to the character in DATA$ where the contents of SEARCH$ can be found. If a match is not found, then the INSTR function will return a zero. Being the author of ZX PRO/FILE program, I perked right up when I discovered INSTR, because it is very similar to Pro/File’s search routine.

I ran some informal speed tests using INSTR and discovered that this function can search through 16,000 characters in somewhere around 5 seconds. That’s not nearly as fast as Pro/File, but still its quite respectable. To have a command like this in Basic is very valuable, indeed.

Programs & Prose

Procedures are the most exciting new functions available. They are second generation GOSUBS which are easy to follow and a joy to implement, because like variables, you give them names. However, you give them English names. To run a procedure you just type the name on a program line. The computer keeps track of everything else: where it’s going, where it’s coming from, etc. [This is very similar to Pascal language in structure, but with the programming ease of Basic.-ed]

If you have ever written programs which make use of subroutines, I’m sure you can see the similarity. The problem with subroutines, however, is that if you make heavy use of them (e.g., GOSUB to a GOSUB to a GOSUB), it doesn’t take long before you’re up to your neck in Gosubs and you don’t know if you’re coming or going.

QL’s procedures are inherently easier to keep track of because the name you give the procedure can describe exactly what the procedure is intended to do.

There’s another advantage to procedures. Variables used within one can be LOCAL to the procedure itself. In other words, you can use the variable X in several different procedures, as well as in the main body of the program. The computer will keep them all separate even though they have the same name. Gone are the hassles of Basic bugs because you accidently changed the value of some variable.

After you define your procedures and call upon them using their very natural names, your program will look more like written prose than a program. This is extremely helpful when you look at your listing and try to make sense out of your program. Procedure names will tell you just what a group of lines is supposed to do.

To give you an idea of what a “procedural” QL program looks like, take this hypothetical listing of a program that moves a man through a maze:

  1 REMark Main body of program is here
10 Generate_a_maze
20 REPeat maze_wander
30 move_the_man
40 AT line,column: print man$
50 END REPeat maze_wander
60 REMark everything that follows is
a procedure
70 REMark
80 REMark
90 REMark
100 DEFine PROcedure Generate_a_maze
.
. lines to make the maze
.
200 END DEFine
210 REMark
220 REMark
300 DEFine PROcedure move_the_man
.
. lines to change position of man
.
350 Test_for_walls
400 END DEFine
410 REMark
420 REMark
500 DEFine PROcedure Test_for_walls
.
. lines to check man's position
. against walls of the maze
.
600 END DEFine

Conclusion

If this piece has whet your appetite for a QL, its not surprising. You could do a lot worse than opting for a QL. From what I’ve seen of other versions of Basic (Apple II, Commodore 64, ZX, and Microsoft/SANYO), Super Basic beats them all hands down for ease and flexibility of programming.

FLASH!!

Right now, Sinclair is sending out brochures and order forms to everyone who asked to be put on their mailing list. If you do not receive information about the QL from Sinclair, you can request a brochure or even place an order by writing to Sinclair Research, Dept. SWN, 1 Sinclair Plaza, Nashua, NH 03061.

The price for the QL is $499.00 plus $12.00 for shipping. Sinclair informs us that Visa and MC are accepted, and that delivery time is 4 to 6 weeks.