AOH :: FORTHAPP.TXT
This is a general description of the forth language, with additional stuff about
|
And Now ... ProFORTH
Are you addled by Applesoft? Perturbed with Pascal? Baffled by BASIC? FORTH is a programming language that might be just your cup of tea. Did I say language? Yes, but also an interpreter, compiler, editor, linker, and operating system all rolled into 8K bytes of memory. Apple-Dayton is pleased to announce the availability of ProFORTH, a FORTH language system running under ProDOS. ProFORTH is derived from the public domain FIG FORTH produced courtesy of the FORTH Interst Group (FIG) of San Carlos, California.
I. Backround
Beware! FORTH is said to be addictive and devotees are even more partisan than Pascal programmers (although not as bad as C hacks). Leo Brodie, in his charming introductory text "Starting FORTH", warns that "few ... ever go back to other languages." What is this FORTH that it garners such oblique praise?
FORTH is fast, compact, and transportable. More significantly, it has some Real World use: it controls a peach sorter for a California cannery; it runs the Craig Language translator; and, on a PDP-11, it controls an entire observatory including radio telescope data acquistion and analysis.
FORTH was developed by Charles H. Moore (late of MIT, Stanford, and the National Radio Astronomy Observatory at Kitt Peak) to suit his needs for a portable, high-level language which was fast enough for process control (using a computer to operate other machinery) yet small enough to run on a minimal system. This combination of fast and small is a paradox in most programming languages yet FORTH is just that - fast and small.
To make the most out of very little computer, FORTH minimizes the overhead of calling a subroutine; indeed, the whole language is built on functions that are nested subroutine calls. According to author John S. James, "The programmer keeps defining new words (new functions) from old ones until, finally, one of them is the whole job." This process makes FORTH programs nearly as fast as those produced by the best optimizing compilers yet more compact than equivalent assembly code.
To bring up FORTH on a new computer, only a handful of primitive routines need to be coded in assembly language. The entire remainder of the system is incrementally built up from these in FORTH. Such an implementation is called "threaded": the invocation of a newly defined word causes the system to follow the thread back through previously defined words until the desired result is obtained. This is not unique to FORTH but is common in FORTH implementations. The machine language programmer might imagine an assembler with recursive, re-entrant macros and arbitrarily extensible opcodes. The Pascal afficianado might see it as an interactive p-machine with user defined p-codes. The BASIC programmer will mostly be impressed.
The FORTH Interest Group (FIG) of San Carlos California has done much to foster the growth of this unusual language by making available public domain versions of their FIG-FORTH system. FIG, as well as commercial producers, have co-operated in the work of the FORTH International Standards Team to make the basic FORTH programming environment standard on a variety of machines. The portability of FORTH is thus exceptional. It is avialable on most personal computers (Apple, Macintosh, TRS-80, Commodore) and all major microprocessors (6502, 6800, 6809, 8080, 8085, 8086, 8088, 68000, PACE, LSI-11, and Z-80). Says Moore, "FORTH is the first language that has come up from the grass roots. It has been honed against the rock of experience before being standardized."
II. What you need
To run ProFORTH you need an Apple ][, ][+, //e or //c and one or more disk drives. An 80 column card and printer are usefull. ProFORTH itself consists of three disks: 1) /FORTH is the system disk including source code for the editor, a 65C02 assmebler and several utilities (one of which provides for conversion of old DOS 3.3 screens to ProDOS format). 2) /TUTORIAL is an interactive FORTH tutorial; this one runs automatically when you boot the disk and has code for creating your own auto-run system. 3) /GLOS is a collection of ProDOS text files including glossaries for the FORTH and ASSEMBLER vocabularies as well as this guide. You can use your favorite word processor to print these. In the absence of a word processor, there is a BASIC program included to format the files for an 80 column printer.
Beyond this, I highly recommend the Byte, August, 1980 (McGraw-Hill, Peterborough, New Hampshire 03458) issue entitled The FORTH Language. It includes an historical account of FORTH by Moore, a tutorial introduction by John James, and a lucid treatment of FORTH extensibility by Kim Harris. Leo Brodie's textbook "Starting FORTH" (Prentice-Hall, Englewood Cliffs, New Jersey 07632) is without peer. This is one of the few computer books that starts at the begining and assumes nothing but that the reader is familiar with English; the illustrations are ingenious without being ingenuous.
III. Creating a custom system
First, use the ProDOS Filer (or any disk copier) to make working copies of the ProFORTH disks. Then print out the glossaries from /GLOS for future reference and boot the tutorial /TUTORIAL. Running the tutorial is (or should be) self explanatory. When you feel comfortable with ProFORTH and have some idea of how the editor works, boot your working copy of the system disk /FORTH.
Unlike /TUTORIAL, which has several important words already added to its dictionary, /FORTH has a bare bones dictionary with just enough words defined to make ProFORTH work. By loading new definitions from disk you can add your own words (or even whole vocabularies) to this basic dictionary to create a custom system. FORTH organizes its disk space into 1024 byte chunks called screens. Screen one of /FORTH is devoted entirely to a list of other screens which are then loaded to make an extended FORTH system. You can examine this list by entering the command
1 LIST
Note that FORTH commands are capitalized here for clarity but the system recognizes the commands just as well when typed in lower case. To load screen one and cause the various components listed to be compiled into the working dictionary, simply enter
1 LOAD
The dictionary thus created exists only in the computer's memory. To save this dictionary to disk for future reference, without the need to re-compile it each time, just LOAD screen two with the command
2 LOAD
The commands contained on screen two modify the system's various pointers to reflect the newest dictionary entries (so they can't be lost by an inadvertant FORGET command) and force the entire dictionary to be saved on disk. The new dictionary replaces the old one. That's why your working with a copy. Aren't you?
Before screen two is used, you can undo any experimental LOADs with the COLD command. After screen two is LOADed, the dictionary additions are permanent for that disk but you can always start over with a fresh copy of the master.
The various components of the system are provided in this fashion to allow you to modify or even replace whole pieces of the system. You can edit and LOAD screen one to get just the list of things you want. You might want to include the ASSEMBLER or a different collection of utilities in your working system. To see an index of the various screens on /FORTH, use the INDEX command (see the FORTH glossary on /GLOS). The INDEX command prints a list of the first line of several screens to give a rough idea of what each screen contains.
Once you have your working /FORTH disk, make a copy of it and use the ProDOS system utilities to rename it something like /BACKUP. If you have a second drive, you can use this disk as you work to hold a backup of whatever you're working on. Put /BACKUP in any other drive and open the file of screens thereon using the command
OPEN /BACKUP/F.DISK
Since the file is opened by name it doesn't matter what drive it's in. Just don't try to use the same drive for two different disks or ProDOS will get lost. While the screens on /FORTH are numbered from 0 through 99, the screens of any other open file are numbered from 100 to however many screens there are in the file. Since the file of screens on /BACKUP (named F.DISK in this case) is just a copy of the original, it contains 100 screens numbered 100 through 199. When you are finished with a particular disk, it is prudent to use the CLOSE command before taking the disk out of the drive. When you are done with ProFORTH entirely, use the BYE command to exit back to ProDOS. BYE automatically flushes and closes any open files.
You can use the editor's COPY command to copy a screen from one disk to another. The command BLOCKS works like COPY for a range of screens. For instance, if you've created a program on screens 50 though 55 of /FORTH, you can backup those six screens on /BACKUP using the command
50 150 6 BLOCKS
The original six screens will now appear on both screens 50 through 55 (on /FORTH) as well as screens 150 through 155 (on /BACKUP). COPY and BLOCKS also work for moving screens around within a single disk file.
If a particular screen gets hopelessly mangled during editing, you can prevent in from being saved to disk by using the command EMPTY-BUFFERS. Any subsequent reference to that screen will cause the original, un-edited contents of the screen to be loaded from disk. If the copy on disk gets messed up, you can replace it with the backup by COPYing it from /BACKUP. You have been backing things up as you go havn't you?
IV. Meta-compiling
The extensibility of FORTH invites a proliferation of variations on a theme. In fact it is possible to write FORTH code which generates the entire FORTH system: a so-called metacompiler suitable for creating code for another system or even another processor. Any decent compiler should be able to compile itself, eh? Unfortunately, this implementation is not that robust. While I've endeavored to make this system as flexible as possible by providing source code for the editor and assembler etc., veteran hackers will want the capability to make changes to this system at the most fundamental level.
One approach is to begin with the machine language source code for the ProFORTH kernel of word definitions. Machine readable scource code for the ProFORTH system and dictionary suitable for assembly using Apple's ProDOS Assembler is available from me for $20 to cover the cost of disks, postage, handling, and coffee. Address inquiries to
John B. Matthews, M.D.
6415 Tantamount Lane
Dayton, Ohio 45449
(513) 435-8887
V. Miscellany
The ProFORTH system itself is freebies. Non-profit distribution by schools, clubs and user groups is encouraged. The only limitation on ditribution is that it remain free. The system works well for me but I can offer no warranty. (Apple-Dayton, Inc. warrants library disks sold to its members to the extent of replacing damaged media, but that's all.) I'll try to provide what support I can. Telephone calls risk finding me asleep in which case anything I say is suspect. Written inquiries with a SASE will at least be answered when I am awake. FORTH oriented programming tips and articles will be promptly edited and published in the Apple-Dayton Journal.
Special thanks to William F. Ragsdale of the FORTH Interest Group who wrote the original 6502 version of FORTH; to William D. Wurzel, M.D. of Washington Apple Pi whose Apple version of FORTH offered enormous insight; to Kurt M. Olsen of Apple-Dayton who inspired this project; and to James E. Hopper of Apple-Dayton who insisted that the delete key ought to work (and so it does).
*** John B. Matthews, M.D. ***
Make REAL money with your website!
The entire AOH site is optimized to look best in Firefox® 2.0 on a widescreen monitor (1440x900 or better).
Site design & layout copyright © 1986-2008 AOH
We do not send spam. If you have received spam bearing an artofhacking.com email address, please forward it with full headers to abuse@artofhacking.com.
