FORTH: A STATUS REPORT

X3J14 Technical Committee votes dpANS Forth

Jack J. Woehr

Jack is a senior project manager at Vesta Technology Inc. in Wheat Ridge, Colorado. He is a member of the ANS/ASC X3J14 Technical Committee for ANS Forth and is currently Chapter Coordinator for the Forth Interest Group. Jack can be reached as jax@well.UUCP, as JAX on GEnie, or as the Sysop of the RCFB BBS, 303-278-0364.


Forth has always been the high-level language most tightly coupled to hardware, in particular to 16-bit two's-complement hardware. X3J14 has attempted to describe Forth in an architecture-independent fashion. Although laudable in theory, this has striking practical implications which are reverberating throughout the Forth community, as professionals and enthusiasts ponder the fruit of X3J14's labors. The document's description of Forth, which will now be passed upwards through the labyrinthine ANSI procedure, is a radical departure from previous descriptions.

X3J14 has had to reconcile conflicts between Forth theory and modern practice. Furthermore, the proceedings have faced the perennial Forth problem of establishing what "common and accepted industry practice" is for a language community whose favorite joke is "If you have seen one Forth, you have seen...one Forth;" and whose founder pronounced that "...Forth is more of an approach than a specification for a programming language," and that "Standards are wonderful: Everyone should have one."

The X3J14 Technical Committee has taken a different viewpoint: Programming language environments standardized under recognized proceedings are more commercially viable than programming language environments not so standardized. Most members of the Technical Committee hope that an American National Standard Forth will ameliorate the heretofore negative opinion of some project managers, who view Forth as merely a hacker's language.

The ANS/ASC X3/X3J14 Technical Committee for ANS Forth met in Boulder, Colo. from 7/30 to 8/3, 1991 and confirmed its 19:1 vote to forward the present BASIS document to ANSI SPARC (Standards Planning and Review Committee, a supervisory body). Upon SPARC approval, the "dpANS" (draft proposed ANS) document, will enter a 4-month period of public review that will ultimately lead to the first American National Standard Forth. Any technical changes that arise during the review period, mean another vote by X3J14 to place the revision into a new public review cycle.

Consider first of all that two previous industry (albeit non-ANSI) standards for Forth explicitly described Forth as a threaded interpreter. That is certainly the classic implementation of Forth and the strategy originally chosen by creator Charles Moore, but many modern Forths are not threaded interpreters. Some are based on a Forth instruction set in microcode or in silicon. Others compile optimized machine code or execute from token lookup tables.

Certainly Forth has detached itself in the marketplace from 16-bit machines and even (in the case of FIG-Forth for the Cray) from two's-complement architecture, a move recognized by X3J14 in its declaration that "This standard allows one's complement, two's complement, or sign-magnitude representations," the minimum commonality allowing all these representations to co-exist in a Forth standard, being that, "In all these systems, arithmetic zero is represented as the value of a single cell with all bits clear." (X3J14 dpANS-2 3.3.2.)

Until now, novel implementations (although clearly and recognizably Forth and often a joy to use in projects) have had to bear the stigma and economic disadvantage of being nonstandard.

The two notable results of the four-year odyssey of X3J14 have been: 1. A masterpiece of a dpANS, which states the eternal verities of the Forth environment while abstracting them from implementation details to the greatest extent possible; 2. controversy, the spice without which the food of the Forth programmer loses its savor.

The Forth word NOT is paradigmatic of the inconsistencies in Forth practice which X3J14 has had to resolve. NOT is not in dpANS. Where did it go? Thereby hangs a tale.

Forth has, for a long while, possessed the words AND, OR, XOR, and NOT. While the first three were always bitwise operators, in early Forths NOT was usually a logical operator. NOT's logical status was enshrined in Forth-79, which mandated that the result of the expression HEX FFFF NOT 1234 NOT = be a TRUE flag in Forth-79, and all bits set in Forth-83 and the proposed ANS Forth. (Note that "all bits set" could be referred to conveniently as "negative one" [1] in Forth-79 and Forth-83. Such shorthand is unavailable to ANS Forth, however, as "all bits set" on a 16-bit one's complement machine is "negative zero" [!?] and on a 16-bit sign-magnitude machine "HEX-7FFF".)

Forth-83 changed the meaning of NOT; it became symmetric with AND, OR and XOR, a bitwise operator, so that HEX FFFF NOT becomes zero (0) and HEX 1234 NOT becomes HEX EDCB.

This seemingly reasonable alteration flew in the face of nearly the entire installed base of Forth systems at the time the change was made. To this day, the economic and religious conflict between the "logical NOTters" and the "bitwise NOTters" is unresolved. Therefore, ANS Forth will possess the operators 0= (the equivalent of logical NOT) and INVERT (the equivalent of bitwise NOT), but not NOT.

Similarly, Forth-79 mandated that integer division with one negative operand return a symmetric result, whereas Forth-83 imposed floored division. Both methods of division yield equally valid results, in that the divisor times the quotient plus the remainder (or "modulus," as it is called in floored division) equal the original dividend. The results, however, are different! Floored integer division is useful in rotary motion and robotics and matrix operations. Symmetric division, on the other hand, is alleged to return a result closer to the user's expectations. Partisans of both methods exhibit a zeal akin to that found in the eleventh century controversy between the Eastern and Roman church over the nature of the paraclete.

X3J14's compromise was this: Primitives FM/MOD (d n1 -- n2 n3, floored) and SM/REM (d n1 -- n2 n3, symmetric) are to be provided for both methods of signed integer division. The default behavior of /MOD and related words can be based on either primitive, as the implementor (read "the implementor's customer") pleases. The portable Standard Program, which is dependent on the behavior of signed integer division with negative operands, can either execute test cases to decide what sort of system it is running under or use the appropriate primitive to ensure the desired results.

X3J14 has also tackled the thorny problems of Forth features that are by now extremely widespread but have never appeared in an industry standard; examples are local variables, floating point mathematics, and multitasking. Of these, multitasking has proven the most intractable, with the proposed dpANS providing only guidelines for the Standard Program in the face of widely varying industry practice.

The proposed ANS Forth elucidates in great detail the twin concepts of the Standard System and the Standard Program. Extensive documentation requirements are imposed on both the implementor of a Standard System and the author of a Standard Program that has any particular environmental dependencies.

The proposed Standard is layered in several word sets, each with its own glossary and extensions. The word sets are: Core, Block, Double, Error-Handling, Facility, File-Access, Floating Point, Locals, Memory-Allocation, Programming-Tools, Search Order, and String. A Standard System need only possess the Core word set, and even so, "[The] Standard does not require that all words be provided in executable form. The implementor may choose to provide word definitions, including definitions of words in the core word set, in source form only. This is acceptable as long as a clearly documented mechanism exists for adding the word definitions to the dictionary." (X3J14 dpANS-2 4.1.)

Several implementations of portions of the proposed Standard already exist. Former DDJ columnist and current X3J14 member Martin Tracy attempts to keep pace with the various levels of BASIS in his Zen Forth system for MS-DOS machines, available for download from many Forth telecom outlets. (See also "Zen for Embedded Systems," by Martin Tracy, DDJ January 1990.)

Gordon Charlton, secretary of FIG-UK, has informed the Technical Committee that his organization is implementing the proposed standard on a 6809 platform. I have implemented in my JAX4TH on the Amiga all of the word sets with their extensions except for Floating Point, Programming-Tools, and Locals; it should be hitting the BBSs about the time you read this.

Despite the traditional annual announcement of the "Death of Forth" (this year the fool's cap was snatched from John Dvorak and Jerry. Pournelle's heads by Steve Gibson, who averred in the July 15 Infoworld that "Much like Latin, Forth is a dead language...with a history"), Forth is alive and thriving around the world, and in particularly good health in the field of embedded systems. Forth programmers have a great deal at stake in an American National Standard Forth, and my hope is that as many as possible will participate in the public review period and lend their experience and wisdom to the task of bettering the viability of commercial Forth programming.


Copyright © 1991, Dr. Dobb's Journal