next up previous
Next: No messing with

Using ANS Forth:

A report from the trenches

We will take a look at the practicalities of using ANS Forth systems and see what present systems are providing.

What ANS Forths are available ?

The simple answer is: none

There are no Forth systems around that satisfy the ANS standard document as it is strictly interpreted.

The primary reason for this is the expense of the offical standard document, and it is not proper to claim standards compliance to the draft standard.

Fortunately, this is of no real practical impact. There are several systems available that are modeled on the draft standard; they are not officially standard, but for all practical purposes they are standard systems.

All of these systems are in the public domain or shareware, they include

The last two in the above list are not strictly compliant, but are close enough to put in this list.

There are no commercial systems that claim compliance.

There is are two pieces of software that you can use to test compliance to the standard:

Loading the system (MS-DOS and Unix)

These systems are ``toolbox'' Forth systems ---- Forth is only one tool in the programmers toolbox. Source files are edited from outside of Forth, external debugging tools are also required as no special debuggers are provided from within these Forths. (An excellant ANS debugger is the one written by Joerg Plewe, it was published in Forth Dimensions, XVII, Number 1).

To load these Forths, give the executable name on the command line listing any files to initially load as command line arguments. Various command line switches can be used to set up the initial behavior of the system (for example PFE can be told to be case sensitive, instead of the default non-sensitive).

There is no default configuration file that is read at startup.

ThisForth can be told to interpret the command line arguments and not just treat the arguments as file names to load.

Under Unix/Linux, both ThisForth and PFE can be run as stand-alone scripts (in place of perl or Bourne shell scripts) by placing the following line as the first line of the Forth source file that you want to run:

#! /usr/local/bin/forth

To run the program, just type the name of the file.

Once the system is running, external files can be loaded and interpreted through standard ANS words, e.g.:

s" filename" included

this is equivalent to the FPC sequence,

fload filename

A file can also be loaded and interpreted under program control by opening a file and including it, s" filename" r/w open-file
abort" file open failed" include-file

File I/O

We have seen a little bit of how file I/O is handled.

Personal note: ANS Forth provides for Blocks or Files. When running Forth on top of an operating system that provides its own file system, I find Blocks to be impratical. They are not compatible with all the other tools that I use external to Forth itself for managing my source code.

A file is opened with the open-file word which returns a file handle and a success/failure flag. This handle is then used for subsequent access to the file.

The File Access wordset is fairly minimal, it provides the ability to get/set a position within a file and to read/write bytes or lines. There are no words to directly read/write a number in/to an ASCII file. For reading one needs to read in the characters and interpret them as a number separately. For writing, an integer has to be formatted as characters and then written out. A separate set of words are needed for this.

What is REALLY different

next up previous
Next: No messing with

Skip Carter
Mon Feb 26 08:26:58 PST 1996