ZX Computing


Forth

Publisher: Sinclair Research
Machine: Sinclair ZX81

 
Published in ZX Computing #11

Forth

Among the latest software to receive Sinclair's stamp of approval is Artic's Forth, for the 16K ZX81 or the 48K Spectrum, of which I have the ZX81 version.

Forth is another computer language, which is ten times faster than Basic and four times more compact. What makes it really powerful is the ability to make up your own functions called 'words'. Each word has a name (by which you refer to it) and a definition (what it does). Each new word is entered into the Forth dictionary. Once a word has been entered, every time you type in the name of the word, its definition is carried out. You could now define another word which contains the previous word you have just entered into the Forth dictionary and/or any other word in the dictionary; so, after hours of programming, your brilliant program will be the definition of just one word.

The whole Forth package is nicely presented and comes in a double-sized cassette case along with a Forth User's Manual, a Forth Editors' Manual and a keyboard overlay. When the main program has loaded, it autoruns and greets you with:

'ZX81 Forth. Artic Computing, 7294 bytes free.'

and waits for your input. The program does not use single key entry like the ZX81's Basic, and as far as numbers go you can use any base from 2 to 36.

Inside the Forth dictionary there are already over 100 word definitions. To enter a new word into the dictionary you use for exampple;

: used to begin a definition

PRINT the example name of the new word

. Forth the Forth words defining what to do

; used to end a definition

If the above were entered, every time you enter the name of the word, i.e. PRINT, Forth would be printed at the to right of the screen. '.' is the Forth word for PRINT.

At any time, the contents of the dictionary can be listed using VLIST, and any words you no longer want can be erased using:

FORGET (name of word)

and to clear al the words you have written from the dictionary you can enter:

COLD

If the worst comes to the worst and you get fed up with Forth you can enter:

BYE

and say bye, bye to Forth as it returns you to Basic.

The unusual thing about Forth is that in Basic to add two numbers together and display them you would type:

PRINT 4 + 2

but in Forth you would type:

4 2 + .

which means place 4 on the stack, place 2 on the stack, add them together placing the result on the stack, and finally, print the result.

You can not do any real programming using you load the Editor. The Editor comes after the main program in four separate parts or 'screens'. Each screen is 1K long and has a number of 0 to 32768 but only one screen can be in memory at any one time. This may seem a problem but Forth comes complete with a fast tape routine and it only takes 30 seconds to load or save a screen, or rather FLUSH, which is the Forth word for save.

As a screen is loaded all the word definitions from that screen are put into the Forth dictionary, and then the next screen can be loaded. Each screen is organised as sixteen lines, numbered from 0 to 15, of 64 characters. This is a method of storing memory and does not affect how you see the TV screen.

The Editor gives you various commands to manipulate the screens using the line numbers, a few of these commands are:

(n stands for a number) Clear screen n Put the following text into line n Delete line n Insert the following text into line n List the current screen

To get the characters shown on the keyboard overlay and in the manuals, you need a QS character board, this can be confusing at times, when you are looking for a character that is not there, but is no real problem.

However, the fact that Forth is so easy to crash is a problem. You only have to type in any graphics character or the wrong word and it crashes, 'bye bye Forth!' Another small fault is that the keyboard overlay is not all that good!

Apart from the above, the Forth package is very good, and anybody who wants to learn another language should get it.

Forth costs £14.95 and is available direct from Sinclair.