Hi-Res has asked Steve Maguire and Evan Rosen, creators of Valforth, to talk to you about a language they believe heralds the future of programming.
We'll caution you. The column may be too advanced for some, but in interests of expanding the readerships' knowledge of programming, Hi-Res presents the following. Your comments will be welcomed by the editors and by Rosen and Maguire.
Critics of Forth, ourselves included, are quick to point out that for all its talent, the language is not yet fully housebroken. For instance, Reverse Polish Notation (RPN) used by Forth can produce disturbing phrases like: X Y Z / +, which is not unlike saying, "The rat the cat I bought caught escaped."
Both phrases will "work," but they are easier on machines than humans.
In Basic the first expression would be: X + Y/Z. (The second expression is already correct English.)
And the "troubles" with Forth don't end there. Because of the way Forth currently uses its stack to pass parameters, programmers have to train themselves to picture a sequence before operations may occur. This can be serious nuisance.
Well, why Forth at all, then? We'll give you two convincing reasons right here, though there are many more.
In Atari Basic, the program
100 FOR X = I TO 30000: NEXT X
runs in just about 64 seconds. In Valforth the equivalent program
TEST 30000 0 DO LOOP;
runs in 3.2 seconds.
Another reason why you might like Forth is that it is extensible. This means that you can invent new kinds of data structures or other, stranger animals as your program. For example, if you wanted a lookup table structure in your program, you could put one in as simply as this:
: LOOKUP <BUILDS DOES> SWAP 1- 2* +;
No fooling. Now, the command LOOKUP is not the table itself. LOOKUP creates lookup tables roughly the same way that DIM in Basic defines arrays. To use LOOKUP to define a table of, say, days in each month, we would do:
Then, by saying, for example, 6 MONTH-TO-DAYS, the number 30, for 30 days in June, would be left on the stack. Any number of other lookup tables could also be generated by LOOKUP. This kind of flexibility is hard to beat. As a matter of fact, we have used this same extensibility in-house to produce a very nice solution to the stack manipulation problem, without sacrificing speed. We hope to release it in a few months.
Varieties of Forth
Which Forth? Virtually all Forths available for the Atari are based on the FIG (Forth Interest Group) model for 6502 by William Ragsdale, so there is relatively good code compatibility. There are currently about a half-dozen Forths for the 400/800's. In approximate chronological order of appearance, they are: Coin-op Forth, a sort of inhouse version at Atari; Sunnyvale Forth, a public-domain version from a users group there (?); QS Forth, from Quality Software; PNS Forth from Pink Noise Studios; APX Forth, from Atari; Ataforth, (sorry, not sure whose); and Valforth, from Valpar International. We wrote and use Valforth, though the programs appearing in this column will generally run without much prodding on any of these systems.
For the newcomer, the best introductory Forth book is Starting Forth, by Brodie, though for some reason the book is not based on the most common dialect of Forth, FIG-Forth. If you already have the book and would like the translation key to FIG-Forth, you can send a stamped, self-addressed envelope to: Starting Forth notes, Valpar International, 3801 E. 34th Street, Tucson, AZ 85716. We'll send you a free copy of the key. (We'll sell you the book, too, if you like.)
In the coming months we'll give you what you seem to want most: novelty, simplicity, and utility. We also hope to hear from you by mail with your questions and comments.
Dr. Quatro will be fielding technical questions as space allows. Here's the Doctor now...
Hello Users, my name is Quatro. Since you haven't written me with any of your questions yet I'll make some up. But next month I want real mail, do you hear?
Good, Now, here is our first letter.
Dear Amazing Dr. Q,
I hope you can settle a question for us. We've been trying to figure out whether Forth is compiled or interpreted. We hear about the "interpreter" in Forth, but since Forth is so much faster than most interpreted languages, something must be up. What?
Chester Viorty, Tennessee
Forth, like the hermit crab, needs to flex itself a little bit to fit into a new shell or microprocessor. But not too much. For Forth, the flexing is performed by an interpreter of a few dozens of bytes. I don't know how the crabs do it. But any way, I myself prefer to think of Forth as the best assembler in the world, needing only to find the best processor in the world on which to run itself. And if I read properly the gleam in the eye of Mr. Charles Moore, who invented Forth in the first place, such a machine is coming. I think this device will do for hardware what Forth is doing for software. Take a heed, you venturesome capitalists! Until then, Chet, Forth is what you might call a little bit interpreted.
Address Letters to:
The Amazing Doctor Quatro
c/o Hi-Res Magazine
933 Lee Rd., Suite 325
Orlando, FL 32810
Evan Rosen and Steve Maguire are the creators of Valforth by Valpar Int. They live and work in Tucson, Arizona and will be contributing a monthly column to Hi-Res on Forth.