D.6.6 Division/modulus rounding direction

Forth-79 specifies that division rounds toward 0 and the remainder carries the sign of the dividend. Forth-83 specifies that division rounds toward negative infinity and the remainder carries the sign of the divisor. ANS Forth allows either behavior for the division operators listed below, at the discretion of the implementor, and provides a pair of division primitives to allow the user to synthesize either explicit behavior.

Words Affected: / MOD /MOD */MOD */

Reason: The difference between the division behaviors in Forth-79 and Forth-83 was a point of much contention, and many Forth implementations did not switch to the Forth-83 behavior. Both variants have vocal proponents, citing both application requirements and execution efficiency arguments on both sides. After extensive debate spanning many meetings, the committee was unable to reach a consensus for choosing one behavior over the other, and chose to allow either behavior as the default, while providing a means for the user to explicitly use both behaviors as needed. Since implementors are allowed to choose either behavior, they are not required to change the behavior exhibited by their current systems, thus preserving correct functioning of existing programs that run on those systems and depend on a particular behavior. New implementations could choose to supply the behavior that is supported by the native CPU instruction set, thus maximizing execution speed, or could choose the behavior that is most appropriate for the intended application domain of the system.

Impact: The issue only affects programs that use a negative dividend with a positive divisor, or a positive dividend with a negative divisor. The vast majority of uses of division occur with both a positive dividend and a positive divisor; in that case, the results are the same for both allowed division behaviors.

Transition/Conversion: For programs that require a specific rounding behavior with division operands of mixed sign, the division operators used by the program may be redefined in terms of one of the new ANS Forth division primitives SM/REM (symmetrical division, i.e., round toward zero) or FM/MOD (floored division, i.e., round toward negative infinity). Then the program may be recompiled without change. For example, the Forth-83 style division operators may be defined by:

: /MOD  ( n1 n2 -- n3 n4 )     >R S>D R> FM/MOD  ;
: MOD   ( n1 n2 -- n3 )        /MOD DROP  ;
: /     ( n1 n2 -- n3 )        /MOD SWAP DROP   ;
: */MOD ( n1 n2 n3 -- n4 n5 )  >R M* R> FM/MOD  ;
: */    ( n1 n2 n3 -- n4 n5 )  */MOD SWAP DROP  ;

D.6.7 Immediacy

Forth-83 specified that a number of compiling words are immediate, meaning that they are executed instead of compiled during compilation. ANS Forth is less specific about most of these words, stating that their behavior is only defined during compilation, and specifying their results rather than their specific compile-time actions.

To force the compilation of a word that would normally be executed, Forth-83 provided the words COMPILE , used with non-immediate words, and [COMPILE] , used with immediate words. ANS Forth provides the single word POSTPONE , which is used with both immediate and non-immediate words, automatically selecting the appropriate behavior.

Words Affected: COMPILE [COMPILE] ['] '

Reason: The designation of particular words as either immediate or not depends upon the implementation technique chosen for the Forth system. With traditional threaded code implementations, the choice was generally quite clear (with the single exception of the word LEAVE), and the standard could specify which words should be immediate. However, some of the currently popular implementation techniques, such as native-code generation with optimization, require the immediacy attribute on a different set of words than the set of immediate words of a threaded code implementation. ANS Forth, acknowledging the validity of these other implementation techniques, specifies the immediacy attribute in as few cases as possible.

When the membership of the set of immediate words is unclear, the decision about whether to use COMPILE or [COMPILE] becomes unclear. Consequently, ANS Forth provides a general purpose replacement word POSTPONE that serves the purpose of the vast majority of uses of both COMPILE and [COMPILE], without requiring that the user know whether or not the postponed word is immediate.

Similarly, the use of ' and ['] with compiling words is unclear if the precise compilation behavior of those words is not specified, so ANS Forth does not permit a Standard Program to use ' or ['] with compiling words.

The traditional (non-immediate) definition of the word COMPILE has an additional problem. Its traditional definition assumes a threaded code implementation technique, and its behavior can only be properly described in that context. In the context of ANS Forth, which permits other implementation techniques in addition to threaded code, it is very difficult, if not impossible, to describe the behavior of the traditional COMPILE. Rather than changing its behavior, and thus breaking existing code, ANS Forth does not include the word COMPILE. This allows existing implementations to continue to supply the word COMPILE with its traditional behavior, if that is appropriate for the implementation.

Impact: [COMPILE] remains in ANS Forth, since its proper use does not depend on knowledge of whether or not a word is immediate (Use of [COMPILE] with a non-immediate word is and has always been a no-op). Whether or not you need to use [COMPILE] requires knowledge of whether or not its target word is immediate, but it is always safe to use [COMPILE]. [COMPILE] is no longer in the (required) core word set, having been moved to the Core Extensions word set, but the committee anticipates that most vendors will supply it anyway.

In nearly all cases, it is correct to replace both [COMPILE] and COMPILE with POSTPONE. Uses of [COMPILE] and COMPILE that are not suitable for mindless replacement by POSTPONE are quite infrequent, and fall into the following two categories:

a) Use of [COMPILE] with non-immediate words. This is sometimes done with the words '-(tick, which was immediate in Forth-79 but not in Forth-83) and LEAVE (which was immediate in Forth-83 but not in Forth-79), in order to force the compilation of those words without regard to whether you are using a Forth-79 or Forth-83 system.

b) Use of the phrase COMPILE [COMPILE] <immediate word> to doubly postpone an immediate word.

Transition/Conversion: Many ANS Forth implementations will continue to implement both [COMPILE] and COMPILE in forms compatible with existing usage. In those environments, no conversion is necessary.

For complete portability, uses of COMPILE and [COMPILE] should be changed to POSTPONE , except in the rare cases indicated above. Uses of [COMPILE] with non-immediate words may be left as-is, and the program may declare a requirement for the word [COMPILE] from the Core Extensions word set, or the [COMPILE] before the non-immediate word may be simply deleted if the target word is known to be non-immediate.

Uses of the phrase COMPILE [COMPILE] <immediate-word> may be handled by introducing an intermediate word (XX in the example below) and then postponing that word. For example:


	: ABC  COMPILE [COMPILE] IF  ;

changes to:

	: XX  POSTPONE IF  ;
	: ABC  POSTPONE XX  ;

A non-standard case can occur with programs that switch out of compilation state to explicitly compile a thread in the dictionary following a COMPILE . For example:

	: XYZ  COMPILE  [ ' ABC , ]  ;

This depends heavily on knowledge of exactly how COMPILE and the threaded-code implementation works. Cases like this cannot be handled mechanically; they must be translated by understanding exactly what the code is doing, and rewriting that section according to ANS Forth restrictions.

Use the phrase POSTPONE [COMPILE] to replace [COMPILE] [COMPILE].

D.6.8 Input character set

Forth-83 specifies that the full 7-bit ASCII character set is available through KEY . ANS Forth restricts it to the graphic characters of the ASCII set, with codes from hex 20 to hex 7E inclusive.

Words Affected: KEY

Reason: Many system environments consume certain control characters for such purposes as input editing, job control, or flow control. A Forth implementation cannot always control this system behavior.

Impact: Standard Programs which require the ability to receive particular control characters through KEY must declare an environmental dependency on the input character set.

Transition/Conversion: For maximum portability, programs should restrict their required input character set to only the graphic characters. Control characters may be handled if available, but complete program functionality should be accessible using only graphic characters.

As stated above, an environmental dependency on the input character set may be declared. Even so, it is recommended that the program should avoid the requirement for particularly-troublesome control characters, such as control-S and control-Q (often used for flow control, sometimes by communication hardware whose presence may be difficult to detect), ASCII NUL (difficult to type on many keyboards), and the distinction between carriage return and line feed (some systems translate carriage returns into line feeds, or vice versa).

D.6.9 Shifting with UM/MOD

Given Forth-83's two's-complement nature, and its requirement for floored (round toward minus infinity) division, shifting is equivalent to division. Also, two's-complement representation implies that unsigned division by a power of two is equivalent to logical right-shifting, so UM/MOD could be used to perform a logical right-shift.

Words Affected: UM/MOD

Reason: The problem with UM/MOD is a result of allowing non-two's-complement number representations, as already described.

ANS Forth provides the words LSHIFT and RSHIFT to perform logical shifts. This is usually more efficient, and certainly more descriptive, than the use of UM/MOD for logical shifting.

Impact: Programs running on ANS Forth systems with two's-complement arithmetic (the majority of machines), will not experience any incompatibility with UM/MOD . Existing Forth-83 Standard programs intended to run on non-two's-complement machines will not be able to use UM/MOD for shifting on a non-two's-complement ANS Forth system. This should not affect a significant number of existing programs (perhaps none at all), since the committee knows of no existing Forth-83 implementations on non-two's-complement machines.

Transition/Conversion: A program that requires UM/MOD to behave as a shift operation may declare an environmental dependency on two's-complement arithmetic.

A program that cannot declare an environmental dependency on two's-complement arithmetic may require editing to replace incompatible uses of UM/MOD with other operators defined within the application.

D.6.10 Vocabularies / wordlists

ANS Forth does not define the words VOCABULARY, CONTEXT, and CURRENT , which were present in Forth-83. Instead, ANS Forth defines a primitive word set for search order specification and control, including words which have not existed in any previous standard.

Forth-83's ALSO/ONLY experimental search order word set is specified for the most part as the extension portion of the ANS Forth Search Order word set.

Words Affected: VOCABULARY CONTEXT CURRENT

Reason: Vocabularies are an area of much divergence among existing systems. Considering major vendors' systems and previous standards, there are at least 5 different and mutually incompatible behaviors of words defined by VOCABULARY. Forth-83 took a step in the direction of run-time search-order specification by declining to specify a specific relationship between the hierarchy of compiled vocabularies and the run-time search order. Forth-83 also specified an experimental mechanism for run-time search-order specification, the ALSO/ONLY scheme. ALSO/ONLY was implemented in numerous systems, and has achieved some measure of popularity in the Forth community.

However, several vendors refuse to implement it, citing technical limitations. In an effort to address those limitations and thus hopefully make ALSO/ONLY more palatable to its critics, the committee specified a simple primitive word set that not only fixes some of the objections to ALSO/ONLY, but also provides sufficient power to implement ALSO/ONLY and all of the other search-order word sets that are currently popular.

The Forth-83 ALSO/ONLY word set is provided as an optional extension to the search-order word set. This allows implementors that are so inclined to provide this word set, with well-defined standard behavior, but does not compel implementors to do so. Some vendors have publicly stated that they will not implement ALSO/ONLY, no matter what, and one major vendor stated an unwillingness to implement ANS Forth at all if ALSO/ONLY is mandated. The committee feels that its actions are prudent, specifying ALSO/ONLY to the extent possible without mandating its inclusion in all systems, and also providing a primitive search-order word set that vendors may be more likely to implement, and which can be used to synthesize ALSO/ONLY.

Transition/Conversion: Since Forth-83 did not mandate precise semantics for VOCABULARY, existing Forth-83 Standard programs cannot use it except in a trivial way. Programs can declare a dependency on the existence of the Search Order word set, and can implement whatever semantics are required using that word set's primitives. Forth-83 programs that need ALSO/ONLY can declare a dependency on the Search Order Extensions word set, or can implement the extensions in terms of the Search Order word set itself.

D.6.11 Multiprogramming impact

Forth-83 marked words with multiprogramming impact by the letter M in the first lines of their descriptions. ANS Forth has removed the M designation from the word descriptions, moving the discussion of multiprogramming impact to this non-normative annex.

Words affected: none

Reason: The meaning of multiprogramming impact is precise only in the context of a specific model for multiprogramming. Although many Forth systems do provide multiprogramming capabilities using a particular round-robin, cooperative, block-buffer sharing model, that model is not universal. Even assuming the classical model, the M designations did not contain enough information to enable writing of applications that interacted in a multiprogrammed system.

Practically speaking, the M designations in Forth-83 served to document usage rules for block buffer addresses in multiprogrammed systems. These addresses often become meaningless after a task has relinquished the CPU for any reason, most often for the purposes of performing I/O, awaiting an event, or voluntarily sharing CPU resources using the word PAUSE. It was essential that portable applications respect those usage rules to make it practical to run them on multiprogrammed systems; failure to adhere to the rules could easily compromise the integrity of other applications running on those systems as well as the applications actually in error. Thus, M appeared on all words that by design gave up the CPU, with the understanding that other words NEVER gave it up.

These usage rules have been explicitly documented in the Block word set where they are relevant. The M designations have been removed entirely.

Impact: In practice, none.

In the sense that any application that depends on multiprogramming must consist of at least two tasks that share some resource(s) and communicate between themselves, Forth-83 did not contain enough information to enable writing of a standard program that DEPENDED on multiprogramming. This is also true of ANS Forth.

Non-multiprogrammed applications in Forth-83 were required to respect usage rules for BLOCK so that they could be run properly on multiprogrammed systems. The same is true of ANS Forth.

The only difference is the documentation method used to define the BLOCK usage rules. The Technical Committee believes that the current method is clearer than the concept of multiprogramming impact.

Transition/Conversion: none needed.

D.6.12 Words not provided in executable form

ANS Forth allows an implementation to supply some words in source code or load as needed form, rather than requiring all supplied words to be available with no additional programmer action.

Words affected: all

Reason: Forth systems are often used in environments where memory space is at a premium. Every word included in the system in executable form consumes memory space. The committee believes that allowing standard words to be provided in source form will increase the probability that implementors will provide complete ANS Forth implementations even in systems designed for use in constrained environments.

Impact: In order to use a Standard Program with a given ANS Forth implementation, it may be necessary to precede the program with an implementation-dependent preface to make source form words executable. This is similar to the methods that other computer languages require for selecting the library routines needed by a particular application.

In languages like C, the goal of eliminating unnecessary routines from the memory image of an application is usually accomplished by providing libraries of routines, using a linker program to incorporate only the necessary routines into an executable application. The method of invoking and controlling the linker is outside the scope of the language definition.

Transition/Conversion: Before compiling a program, the programmer may need to perform some action to make the words required by that program available for execution.

Table of Contents
Next Section