The Journal of Forth Application and Research
ISSN: 0738-2022

Forth Institute

Editorial Board

Author's Guidelines

Authors Index

Volume 7
Volume 6
Volume 5
Volume 4
Volume 3
Volume 2
Volume 1

Valid XHTML 1.0 Strict
Valid CSS!

Volume Three

PDFs provided by FORTH, Inc.
Thea Martin
Number 1: Using and Improving Forth
Lawrence Forsley
Number 2: Proceedings of the 1985 Rochester Forth Conference
Lawrence Forsley
Number 3: Application Languages
Lawrence Forsley
Forth-Based Software for Real-Time Control of a Mechanically-Scanned Ultrasonic Imaging System
E. T. Lynk and H. E. Johnson Jr.
Forth was used as the control software for an ultrasonic imaging system developed at GE/CRD. The system is an "Ultrasonic Macroscope" and is used in industrial "Nondestructive Evaluation" applications. It forms an image by mechanically moving an ultra-sound beam over the surface of the material under test. The beam is tightly focused at a constant depth below the surface to reveal flaw locations within the sub-surface slice. Image acquisition and display functions are performed by two Direct-Memory-Access controllers, using extended memory. Data input, output, and computation all take place concurrently. The system is fully interrupt-driven to free the 11/23 bus for DMA transfers (word transfer rates on the order of tens of KHz).

The application software (which runs on an enhanced fig-Forth-derived kernel) models the imaging system as a cyclic, sequential finite state machine. A state variable is derived from the image line-counter and governs the operations that the CPU must perform. Through the use of interrupts and flags, the output process (which synchronizes the entire operation) functions as if it were driven by an independent processor.

Routines were written to permit high-level access to extended memory and high-level interrupt handlers. Software debugging was facilitated by a "snapshot" routine which captured the "state" of the system. It provided a post-mortem display/dump of the sequence of events, state of flags, variables, etc., at the time each snapshot was taken.

This application was particularly well suited to Forth. Because of the heavy bus usage anticipated at high scan speeds, stand-alone operation is mandatory, regardless of the software environment.

Fast and Flexible Forth Programming in a Femtosecond Laser Lab
Theodore Sizer, II
A software system has been developed in Forth to manipulate, control, acquire, and display experiments which are performed in a femtosecond dye laser laboratory. Requirements placed on the system are that it be user friendly while maintaining both flexibility and speed. The use of vectored execution allows one to satisfy these two requirements while keeping the number of user addressable words to a minimum. This system is currently in use measuring both optical and electrical transients in the terahertz frequency regime. Techniques that are used to control and display the experiments will be explained along with some typical results that this system gives the experimenter.
Stack Frames and Local Variables
George B. Lyons
The stack frame technique for dynamic local variable storage in Algol and descendant languages may be adopted in Forth to expand the number of elements easily handled directly on the stack, reducing the need for variables. The required extensions to Forth can preserve the interactive quality of Forth by using the parameter stack exclusively and by using a built-in set of local variable names rather than an argument list compiler. Special techniques such as wildcard names, code pointer arrays, and modifications of TO can reduce the overhead involved.
Should VARIABLE be an Immediate State-sensitive Word?
Steven M. Lewis
We present an alternative to the word VARIABLE. In the absence of special modifiers, the word returns the contents. Previous use of modifiers allow the word to store or otherwise modify its contents. Unlike previous implementations the word is immediate and modifiers act at compile time allowing run time performance equivalent or superior to that seen with @ and !. The extension of this concept to arrays is also presented.
Readable and Efficient Parameter Access via Argument Records
Bill Stoddart
Abstract / Errata
An Argument Record allows the input parameters and local variables of a high level Forth definition to be accessed by name. Method selection prefixes such as to then become widely applicable, allowing closer action object binding and reducing the proliferation of dictionary words as new data types such as floating point numbers and matrices are introduced. Such enhancements are of particular interest because they can be freely intermixed with classical Forth. Standard Forth techniques for describing compiler extensions prove to be an ideal tool for implementing these enhancements. A package that requires just 1200 bytes of dictionary space is sufficient to provide a wide range of facilities, and produces efficient re-entrant code.
Page 64, 1st paragraph:
: 2ND-GCD ( n1 n2 -- n3   functionally equivalent to 1ST-GCD )
  { num x  num y  0 num remainder }
  BEGIN  val y  WHILE
    val x  val y  MOD   to remainder
    val y  to  x
    val remainder to y
  REPEAT   val x   ;
A Microcoded Machine Simulator and Microcode Assembler in a Forth Environment
A. Cotterman, R. Dixon, R. Grewe and G. Simpson
A Forth program that provides a design tool for systems which contain a microcoded component was implemented and used in a computer architecture laboratory. The declaration of standard components such as registers, ALUs, busses, memories, and the connections is required. A sequencer and timing signals are implicit in the implementation. The microcode is written in a Forth-like language which can be executed directly as a simulation or interpreted to produce a fixed horizontal microcode bit pattern for generating ROMs.

The direct execution of the microcode commands (rather than producing bit patterns and interpreting those instructions) gives a simpler, faster implementation. Further, the designer may concentrate on developing the design at a block level without considering some of the implementation details (such as microcode fields) which might change several times during the design cycle. However, the design is close enough to the hardware to be readily translated. Finally, the fact that the same code used for the simulation may be used for assembly of the microcode instructions after the field patterns have been specified) saves time and reduces errors

A Forth Implementation of the Heap Data Structure for Memory Management
W. B. Dress
The use of the heap for memory management provides the Forth programmer with a versatile tool. Its use speeds program development at the conceptual level by allowing the program designer to consider dynamic arrays, garbage collection, and overlays; and at the implementation stage by providing a framework for easy manipulation of such data structures. An examination of the high-level code leads naturally to examples of these and other techniques of dynamic data management.

The implementation presented here has been used for some time in our Forth-based version of the expert systems language, OPS5. This has resulted in faster execution times for OPS5 programs and has overcome problems in extending the language to the real-time domain.

Object Oriented Extensions to Forth
Dick Pountain
This paper describes an extension to a standard Forth-79 or -83 system that enables programming with objects organised into classes (with subclass inheritance). Objects are activated by sending messages to them, following the model of Smalltalk-80.
Discrete Event Simulation in Forth
Leonard F. Zettel
A Forth-based discrete event simulation system is presented, with words for scheduling events, executing the simulation, or optionally stepping through it. An example problem, the barbershop simulation, is presented and discussed. Forth is shown to have considerable advantage over implementation in conventional procedural languages.
Extending Forth in a Camac Controlled Muon Channel
Robbie Spruit
Control and diagnostic software was developed for a recently commissioned muon channel at TRIUMF. Logistics gave rise to separate efforts in several programming languages. This paper describes the Forth diagnostic package. The choice of programming language is discussed briefly. Several extensions to Forth, and their usage, are shown in the framework of a detailed account of the software implementation. Emphasis is placed on the production of readable code and on the design of constructs that closely model the structure of the application.
Forth in the Computer Numerical Control Environment
John Mullen
In order to help students grasp the concepts of computer-aided manufacture, a small Computer Numerical Control (CNC) workstation was built. It consists of a microcomputer, a vertical mill, a plotter, a printer, and necessary interface electronics. The workstation may be controlled by means of either a Forth-based control language or a CNC language closely following the standards of EIA RS-358-B.

The development of this workstation has been greatly facilitated by the use of Forth, which was used to test electronic driver and interface circuits, to control the plotter and mill, to form a basis for the Forth-like control language, and to implement the EIA standard CNC language. In addition, since the CNC languages are embedded in Forth, the support features of the Forth system are available to the user.

The inherent transportability of Forth combined with a hierarchial modular design results in an implementation that is almost totally hardware-independent and very flexible. This project serves as an extensive demonstration of the utility of the integrated Forth environment in CNC applications

Exception Handling in Forth
Clifton Guy and Terry Rayburn
Forth relies on the discipline of the programmer to provide the benefits of structured languages: readability, predictability and modularity. A difficult class of problem for structured software is the handling of exceptions to the control flow, including errors. Even in properly designed software, a low level module may detect a condition whose proper resolution resides on a higher level. We describe a general implementation for exception handling in Forth that hides the inherent structure violation within a readable control structure which allows return from any nesting depth of Forth words and control structures. Further, this structure is itself nestable to any arbitrary depth.
State Sequence Handlers
Edward B. Rawson
We describe a new type of sequence control structure that allows an ordinary : word to behave as a small state machine. The control structures may be freely mixed with BEGIN, UNTIL, etc., and with IF, ELSE, and THEN, with conventional nesting restrictions. The new structures include analogs of BEGIN, UNTIL, etc., as well as several other words that support terse, readable state machine code.

The normal state variable is replaced by an execution pointer, whose handling is mostly hidden in the source code. Application code never need supply a pointer value. Definitions may be understood as standard Forth procedures, with the understanding that execution may "hang up" in one of the internal loops or called procedures until it is proper to proceed. Repeated calls to the main procedure result in repeated execution of the loop code or the called procedure until continuation is appropriate.

The sequence control structures encourage structured code, make state entry and exit natural, and produce fast, compact, object code. They eliminate the need to assign and manage state numbers.

The structures and several applications are described.

User-Oriented Suggestions for Floating-Point and Complex-Arithmetic Forth Standard Extensions
Ferren MacIntyre and Thomas Dowling
Governmental, industrial, and editorial acceptance of Forth requires that it conform to some recognized, formal standard, (preferably sanctioned by ANSI). Proposed here are standard extension wordsets for floating-point (FP) and complex (CP) arithmetic, based upon three years of extensive use (and rewriting) of the MMSFORTH words with the 8087 numerical coprocessor. The models for the proposed extensions are IEEE 754 for constraints and the HP-15C pocket calculator for scope.

Familiar words are merely preceded by F or C. Many words such as -F- and F\ (for FSWAP F- and FSWAP F/) name single 8087 instructions. Short words are mandatory because of the natural length of FP equations. Less familiar words include -F for negation and FRT2 for FROT FROT, symmetrical with FROT and as often needed.

Left open for community discussion is the choice of FP number indication on input. Large numbers are well represented by an embedded E, as 12.34E56, but 3.E0 is prolix. 3E is confusible with hex, 3. with double-length integer. The European decimal 3, is unique, but some do not like the comma.

Adequate output formatting capability is essential and is provided. Over 100 data types are subsumed under a single "grandfather" defining word, all stored with IS.

Not discussed are possible differences resulting from different IEEE 754 hardware implementations (e.g.: Intel's 8087 and 80287, etc.).

A Wordset for Error Propagation Arithmetic
Ferren MacIntyre
Experimental and observational errors propagate as data are transformed or mathematically manipulated to produce quantities of interest. The mathematics of this propagation are simple, well known, but tedious to apply. Forth proves to be an ideal language for error analysis. Presented here is a short wordset that reduces the mathematical portion of the process (in contrast to its philosophical aspects) to routine coding, supplying the minimum propagated error of any data reduction nearly automatically. Additional words can be built upon the models supplied. Floating point capability is assumed.
Technical Notes:
Run-Time Error Handling in Forth using SETJMP and LNGJMP for Execution Control (or, GOTO in Forth)
Robert J. Paul, Jay S. Friedland and Jeremy E. Sagan
This paper discusses and provides two Forth implementations of the SETJMP/LNGJMP concept for error handling in applications which have words nested many layers deep. SETJMP and LNGJMP may be familiar to programmers who have worked with UNIX/C environments. A SETJMP is paired with a LNGJMP, which when executed later, will return control to the code following the SETJMP, passing an appropriate value on the stack. In essence, this creates the equivalent of the GOTO statement in Forth. In most Forth applications a word at each level returns an error or success code which is processed before continuing. The use of SETJMP/LNGJMP eliminates the nesting of IF...ELSE...THEN or BEGIN...UNTIL statements by transferring control to a level where all error conditions may be handled. SETJMP and LNGJMP may be nested to handle local as well as global situations. These constructs reduce code overhead and produce code which is easier to follow. SETJMP and LNGJMP are ideal programming constructs for error handling since they allow control flow to be optimized.
Plotter Drivers as an Exercise in Forth Wordset Design
A. Richard Miller and Thomas B. Dowling
Three levels of driver design are discussed for a typical X-Y plotter. A minimum driver merely permits Forth to mimic the plotter's internal BASIC command set. A more elegant one transforms the same command into a more Forth-like and more English-like wordset. Finally, the command set is modified and vectored into the existing MMSFORTH TGRAPH (Turtle Graphics) utility. This transforms the plotter into an optional video screen to which one can output TGRAPH graphics routines without any modification. Source code for a simple Forth implementation for the Radio Shack FP-215 Flat-bed plotter is included, and can be adapted to many similar plotters.
Conference Abstracts:
1985 FORML Conference
Conference Proceedings:
1985 Rochester Forth Conference on Software Productivity and Project Management.
Call for Papers:
1986 Rochester Forth Conference on Real-Time Artificial Intelligence, Systems and Applications
Journal of Forth Application and Research issue on Embeddings of 5th Generation Languages in Forth
Calendar of Events:
Number 1
Number 3
Number 4
For Number 1