Forth 2012
Forth 2012
Forth 2012
Contents
Contents v
Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vi
Proposals Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii
200x Membership . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . x
1 Introduction 13
1.1 Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.2 Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.2.1 Inclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.2.2 Exclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.3 Document organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.3.1 Word sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.3.2 Annexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.4 Future directions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.4.1 New technology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.4.2 Obsolescent features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3 Usage requirements 22
3.1 Data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.1.1 Data-type relationships . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.1.2 Character types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.1.3 Single-cell types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.1.4 Cell-pair types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.1.5 System types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.2 The implementation environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.2.1 Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.2.2 Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.2.3 Stacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
3.2.4 Operator terminal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.2.5 Mass storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.2.6 Environmental queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.2.7 Obsolescent Environmental Queries . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.3 The Forth dictionary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
iii
CONTENTS Forth 2012
4 Documentation requirements 38
4.1 System documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
4.1.1 Implementation-defined options . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
4.1.2 Ambiguous conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
4.1.3 Other system documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
4.2 Program documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
4.2.1 Environmental dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
4.2.2 Other program documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
6 Glossary 44
6.1 Core words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
6.2 Core extension words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
iv
Forth 2012 CONTENTS
A Rationale 182
A.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
A.2 Terms and notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
A.3 Usage requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
A.4 Documentation requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
A.5 Compliance and labeling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
A.6 Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
A.7 The optional Block word set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
A.8 The optional Double-Number word set . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
A.9 The optional Exception word set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
A.10 The optional Facility word set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
A.11 The optional File-Access word set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
A.12 The optional Floating-Point word set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
A.13 The optional Locals word set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
A.14 The optional Memory-Allocation word set . . . . . . . . . . . . . . . . . . . . . . . . . . 227
A.15 The optional Programming-Tools word set . . . . . . . . . . . . . . . . . . . . . . . . . . 227
A.16 The optional Search-Order word set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
A.17 The optional String word set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
A.18 The optional Extended-Character word set . . . . . . . . . . . . . . . . . . . . . . . . . . 232
B Bibliography 234
v
Foreword Forth 2012
Foreword
Forth is a language for direct communication between human beings and machines. Forth was invented by
Charles Moore to increase programmer productivity without sacrificing machine efficiency. Using natural-
language diction and machine-oriented syntax, Forth provides an economical, productive environment for
interactive compilation and execution of programs. Forth also provides low-level access to computer-
controlled hardware, and the ability to extend the language itself. This extensibility allows the language
to be quickly expanded and adapted to special needs and different hardware systems. Forth provides for
highly interactive program development and testing.
In the interests of transportability of application software written in Forth, standardization efforts began in
the mid-1970s by an international group of users and implementors who adopted the name “Forth Standards
Team”. This effort resulted in the Forth-77 Standard. As the language continued to evolve, an interim
Forth-78 Standard was published by the Forth Standards Team. Following Forth Standards Team meetings
in 1979, the Forth-79 Standard was published in 1980. Major changes were made by the Forth Standards
Team in the Forth-83 Standard, which was published in 1983.
The ANS Forth committee was formed in 1987 to address the fragmentation within the Forth community
caused not only by the difference between Forth 79 and Forth 83 but the exploitation of technical de-
velopments. Undertaking a comprehensive review of existing implementations they moved away from
prescribing stringent requirements, preferring to describe the operation of the virtual machine, without
reference to an implementation. The ANS Forth Standard was published in 19941 and was adopted as an
international standard in 19972 .
The Forth 200x Standardisation Committee was formed in 2004 to allow the Forth community to contribute
to an updated standard. Changes are proposed and discussed in the electronic media: the usenet news group
comp.lang.forth; the [email protected] email list; the www.forth200x.org
web site. Annual public meeting are held to review and vote on the proposed changes.
This document is the result of the public review meetings first held on October 21–22, 2005 (Santander)
and subsequently on September 14–15, 2006 (Cambridge), September 13–14, 2007 (Dagstuhl), September
25–26, 2008 (Vienna), March 25–27, 2009 (Neuenkirchen, Rheine), September 2–4, 2009 (Exeter), March
24–26, 2010 (Rostock), September 22–24, 2010 (Hamburg), September 21–23, 2011 (Vienna), September
12–14, 2012 (Oxford), September 25–27, 2013 (Hamburg).
vi
Forth 2012 Proposals Process
Proposals Process
In developing a standard it is necessary for the standards committee to know what the system implementors
and the programmers are already doing in that area, and what they would be willing to do, or wish for.
To that end we have introduced a system of consultation with the Forth community:
a) A proponent of an extension or change to the standard writes a proposal.
b) The proponent publishes the proposal as an RfD (Request for Discussion) by sending a copy to the
[email protected] email list and to the comp.lang.forth usenet news group
where it can be discussed. The maintainers of the www.forth200x.org web site will then place
a copy of the proposal on that web site.
Be warned, this will generate a lot of heated discussion.
In order for the results to be available in time for a standards meeting, an RfD should be published
at least 12 weeks before the next meeting.
If a proposal does not propose extensions or changes to the Forth language, but a rewording of the
current document, there is nothing for a system implementor to implement, or a programmer to use.
In such a case, the proposal should be published as a Request for Comment (RfC). The proposal will
be considered, along with any comments, at the next committee meeting.
c) The proponent can modify the proposal, taking any comments into consideration. Where comments
have been dismissed, both the comment and the reasons for its dismissal should be given. The revised
proposal is published as a revised RfD/RfC.
d) Once a proposal has settled down, it is frozen, and submitted to a vote taker, who then publishes
a CfV (Call for Votes) on the proposal. The vote taker will normally be a member of the stand-
ards committee. In the poll, system implementors can state, whether their systems implement the
proposal, or what the chances are that it ever will. Similarly, programmers can state whether they
have used something similar to the proposed extension and whether they would use the proposed
extension once it is standardized. The results of this poll are used by the standards committee when
deciding whether to accept the proposal into the standards document.
In order for the results to be available in time for a standards meeting, the CfV should be started at
least 6 weeks before that meeting.
e) One to two weeks after publishing the CfV, the vote taker will publish a Current Standings. Note
that the poll will remain open, especially for information on additional systems, and the results will
be updated on the Forth200x web page. The results considered at a standards meeting are those from
four weeks prior to that meeting. If no poll results are available by that deadline, the proposal will
be considered at a later meeting.
f) A proposal will only be accepted into the new basis document by consensus of those present at a
standards meeting. If you can not attend a meeting, you should ask somebody who is attending to
champion the proposal on your behalf.
Should a contributor consider their comments to have been dismissed without due consideration, they are
encouraged to submit a counter proposal.
vii
Proposals Process Forth 2012
Proposals which have passed the poll will be integrated into the basis document in preparation for the
approaching standards committee meeting. Proposals often require some rewording in this process, so the
proponent should work with the editor to integrate the proposal into the document.
A proposal should give a rationale for the proposal, so that system implementors and programmers may
see the relevance of the proposal and why they should adopt (and vote for) it. The proposal should include
the following sections, where appropriate.
Author:
The name of the author(s) of the proposal.
Change Log:
A list of changes to the last published edition on the proposal.
Problem:
This states what problem the proposal addresses.
Solution:
An informal description of the proposed solution to the problem identified by the proposal.
Typical use:
Shows a typical use of the word/feature you propose; this should make the formal wording easier to
understand.
Remarks:
This gives the rationale for specific decisions you have taken in the proposal (often in response to
comments in the RfD phase), or discusses specific issues that have not been decided yet.
Proposal:
This is the formal or normative part of the proposal and should be as well specified as possible.
Some issues could be left undecided in the initial RfDs, leaving the issue open for discussion. These
issues should be mentioned in the Remarks section as well as in the Proposal section.
If you want to leave something open to the system implementor, make that explicit, e.g., by making
it an ambiguous condition.
For the wording of word definitions, it is normally a good idea to take your inspiration from existing
word definitions in the basis document. Where possible you should include the rationale for the
definition. Should a proposal be accepted where no rationale has been provided, the editor will
construct a rationale from other parts of the proposal. The proponent should work with the editor in
the development of this rationale.
Reference implementation:
This makes it easier for system implementors to adopt your proposal. Where possible they should be
provided in standard Forth, as defined by this document. Where this is not possible, system specific
knowledge is required or non standard words are used, this should be documented.
Testing:
This should test the feature/words you propose, in particular, it should test boundary conditions.
Where possible test cases should be written to conform with John Hayes tester.f test harness.
viii
Forth 2012 Proposals Process
Experience:
Indicate where the proposal has already been implemented and/or used.
Comments:
Initially this is blank. As comments are made on the proposal, they should be incorporated into the
proposal. Comment which can not be incorporated should be included in this section. A response to
the comment may be included after the comment itself.
Instructions for responding to the poll:
Once the proposal enters the CfV stage, the vote taker will add these instructions to the proposal.
ix
200x Membership Forth 2012
200x Membership
This document is maintained by the Forth 200x Standards Committee. The committee meetings are open
to the public, anybody is allowed to join the committee in its deliberations.
Membership of the committee is open to anybody who can attend. On attending a meeting of any kind a
non-member becomes an observing member (observer). If they attend the next voting meeting, they will
become a voting member of the committee, otherwise they revert to non-member status. An observer will
not normally be allowed to vote, but may be allowed at the discretion of the committee. A member will be
deemed to have resigned from the committee if they fail to attend two consecutive voting meetings.
Currently the committee has the following voting members:
Dr. M. Anton Ertl (Chair) . . . . . . . . . . . . . . . . . . . . . . . . Technische Universität Wien
[email protected] Wien, Austria
Dr. Peter Knaggs (Editor) . . . . . . . . . . . . . . . . . . . . . . . . Independent Member
[email protected] Trowbridge, UK
Willem Botha . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Construction Computer Software (Pty) Ltd
[email protected] Cape Town, South Africa
Andrew Haley . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Red Hat UK Ltd.
[email protected] Cambridge, UK
Dr. Ulrich Hoffmann . . . . . . . . . . . . . . . . . . . . . . . . . . . . . FH Wedel
[email protected] Wedel, Germany
Simon Kaphahn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Independent Member
[email protected] Munich, Germany
Bernd Paysan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Net2o
[email protected] Munich, Germany
Stephen Pelc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . MicroProcessor Engineering Ltd.
[email protected] Southampton, UK
Dr. Willi Stricker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Independent Member
[email protected] Springe, Germany
Leon Wagner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . FORTH, Inc.
[email protected] Los Angeles, USA
Gerald Wodni . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Independent Member
[email protected] Wien, Austria
The following organizations and individuals have also participated in this project as committee members.
The committee recognizes and respects their contributions:
Federico de Ceballos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Universidad de Cantabria
[email protected] Santander, Spain
x
Forth 2012 200x Membership
xi
200x Membership Forth 2012
xii
Forth 2012 1. Introduction
1 Introduction
1.1 Purpose
The purpose of this standard is to promote the portability of Forth programs for use on a wide variety
of computing systems, to facilitate the communication of programs, programming techniques, and ideas
among Forth programmers, and to serve as a basis for the future evolution of the Forth language.
1.2 Scope
This standard specifies an interface between a Forth System and a Forth Program by defining the words
provided by a Standard System.
1.2.1 Inclusions
This standard specifies:
– the forms that a program written in the Forth language may take;
– the rules for interpreting the meaning of a program and its data.
1.2.2 Exclusions
This standard does not specify:
– the mechanism by which programs are transformed for use on computing systems;
– the operations required for setup and control of the use of programs on computing systems;
– the method of transcription of programs or their input or output data to or from a storage medium;
– the program and Forth system behavior when the rules of this standard fail to establish an interpreta-
tion;
– the size or complexity of a program and its data that will exceed the capacity of any specific comput-
ing system or the capability of a particular Forth system;
– the physical properties of input/output records, files, and units;
– the physical properties and implementation of storage.
13
1. Introduction Forth 2012
The “Core” word set, defined in sections 1 through 6, contains the required words and capabilities of a
Standard System. The other word sets, defined in sections 7 through 18, are optional, making it possible to
provide Standard Systems with tailored levels of functionality.
Within each word set, section 1 contains introductory and explanatory material and section 2 introduces
terms and notation used throughout the standard. There are no requirements in these sections.
Sections 3 and 4 contain the usage and documentation requirements, respectively, for Standard Systems
and Programs, while section 5 specifies their labeling.
Sections x.1–x.6 of each word set have the same section numbering as sections 1–6 of the whole document
to make it easy to relate the sections to each other. This may lead to gaps in section numbers if a particular
section does not occur in a word set.
Section 6 of each word set specifies the required behavior of the definitions in the word set and the exten-
sions word set.
1.3.2 Annexes
The annexes do not contain any required material.
Annex A provides some of the rationale behind the committee’s decisions in creating this standard, as well
as implementation examples. It has the same section numbering as the body of the standard to make it easy
to relate each requirements section to its rationale section.
Annex B is a short bibliography on Forth.
Annex C discusses the compatibility of this standard with earlier Forths.
Annex D presents some techniques for writing portable programs.
Annex E is an index of all Forth words defined in this standard.
14
Forth 2012 1. Introduction
15.6.2.1580 FORGET
6.2.2530 [COMPILE]
13.6.2.1795 LOCALS|
This standard designates the following practice as obsolescent:
– Using ENVIRONMENT? to enquire whether a word set is present.
15
2. Terms, notation, and references Forth 2012
The phrase “See:” is used throughout this standard to direct the reader to other sections of the standard that
have a direct bearing on the current section.
In this standard, “shall” states a requirement on a system or program; conversely, “shall not” is a prohi-
bition; “need not” means “is not required to”; “should” describes a recommendation of the standard; and
“may”, depending on context, means “is allowed to” or “might happen”.
Throughout the standard, typefaces are used in the following manner:
– This proportional serif typeface is used for text, with italic used for symbols and the first appearance
of new terms;
– A bold proportional sans-serif typeface is used for headings;
– A bold monospaced serif typeface is used for Forth-language text.
16
Forth 2012 2. Terms, notation, and references
code space: The logical area of the dictionary in which word semantics are implemented.
compile: To transform source code into dictionary definitions.
compilation semantics: The behavior of a Forth definition when its name is encountered by the text in-
terpreter in compilation state.
counted string: A data structure consisting of one character containing a length followed by zero or more
contiguous data characters. Normally, counted strings contain text.
cross compiler: A system that compiles a program for later execution in an environment that may be phys-
ically and logically different from the compiling environment. In a cross compiler, the term “host”
applies to the compiling environment, and the term “target” applies to the run-time environment.
current definition: The definition whose compilation has been started but not yet ended.
data field: The data space associated with a word defined via CREATE.
data space: The logical area of the dictionary that can be accessed.
data-space pointer: The address of the next available data space location, i.e., the value returned by
HERE.
data stack: A stack that may be used for passing parameters between definitions. When there is no possi-
bility of confusion, the data stack is referred to as “the stack”. Contrast with return stack.
data type: An identifier for the set of values that a data object may have.
defining word: A Forth word that creates a new definition when executed.
definition: A Forth execution procedure compiled into the dictionary.
dictionary: An extensible structure that contains definitions and associated data space.
display: To send one or more characters to the user output device.
environmental dependencies: A program’s implicit assumptions about a Forth system’s implementation
options or underlying hardware. For example, a program that assumes a cell size greater than 16 bits
is said to have an environmental dependency.
execution semantics: The behavior of a Forth definition when it is executed.
execution token: A value that identifies the execution semantics of a definition.
find: To search the dictionary for a definition name matching a given string.
immediate word: A Forth word whose compilation semantics are to perform its execution semantics.
implementation defined: Denotes system behaviors or features that must be provided and documented
by a system but whose further details are not prescribed by this standard.
implementation dependent: Denotes system behaviors or features that must be provided by a system but
whose further details are not prescribed by this standard.
initiation semantics: Describes the behavior at the start of some word definitions (those of words defined
with :, :NONAME, CREATE DOES>). Other parts of the specification of these defining words (and
nothing else) refer to initiation semantics.
17
2. Terms, notation, and references Forth 2012
input buffer: A region of memory containing the sequence of characters from the input source that is
currently accessible to a program.
input source: The device, file, block, or other entity that supplies characters to refill the input buffer.
input source specification: A set of information describing a particular state of the input source, input
buffer, and parse area. This information is sufficient, when saved and restored properly, to enable the
nesting of parsing operations on the same or different input sources.
interpretation semantics: The behavior of a Forth definition when its name is encountered by the text
interpreter in interpretation state.
keyboard event: A value received by the system denoting a user action at the user input device. The term
“keyboard” in this document does not exclude other types of user input devices.
line: A sequence of characters followed by an actual or implied line terminator.
name space: The logical area of the dictionary in which definition names are stored.
number: In this standard, “number” used without other qualification means “integer”. Similarly, “double
number” means “double-cell integer”.
parse: To select and exclude a character string from the parse area using a specified set of delimiting
characters, called delimiters.
parse area: The portion of the input buffer that has not yet been parsed, and is thus available to the system
for subsequent processing by the text interpreter and other parsing operations.
pictured-numeric output: A number display format in which the number is converted using Forth words
that resemble a symbolic “picture” of the desired output.
program: A complete specification of execution to achieve a specific function (application task) expressed
in Forth source code form.
receive: To obtain characters from the user input device.
return stack: A stack that may be used for program execution nesting, do-loop execution, temporary
storage, and other purposes.
standard word: A named Forth procedure, formally specified in this standard.
user input device: The input device currently selected as the source of received data, typically a keyboard.
user output device: The output device currently selected as the destination of display data.
variable: A named region of data space located and accessed by its memory address.
word: Depending on context, either 1) the name of a Forth definition; or 2) a parsed sequence of non-space
characters, which could be the name of a Forth definition.
word list: A list of associated Forth definition names that may be examined during a dictionary search.
word set: A set of Forth definitions grouped together in this standard under a name indicating some shared
aspect, typically their common functional area.
18
Forth 2012 2. Terms, notation, and references
2.2 Notation
2.2.1 Numeric notation
Unless otherwise stated, all references to numbers apply to signed single-cell integers. The inclusive range
of values is shown as {from . . . to}. The allowable range for the contents of an address is shown in double
braces, particularly for the contents of variables, e.g., BASE {{2 . . . 36}}.
19
2. Terms, notation, and references Forth 2012
The first paragraph of the semantic description contains a stack notation for each stack affected by execution
of the word. The remaining paragraphs contain a text description of the semantics. See 3.4.3 Semantics.
20
Forth 2012 2. Terms, notation, and references
2.3 References
The following national and international standards are referenced in this standard:
– ISO/IEC 15145:1997 Information technology. Programming languages. FORTH.
– ANSI X3.215-1994 Programming Languages – Forth.
– ANSI X3.172-1990 Dictionary for Information Systems, (2.1 Definitions of terms);
– ANSI X3.4-1974 American Standard Code for Information Interchange (ASCII), (3.1.2.1 Graphic
characters);
– ISO 646-1983 ISO 7-bit coded characterset for information interchange, International Reference
Version (IRV) (3.1.2.1 Graphic characters);
– ANSI/IEEE 754-1985 Floating-point Standard, (12.2.1 Definition of terms).
21
3. Usage requirements Forth 2012
3 Usage requirements
A system shall provide all of the words defined in 6.1 Core words. It may also provide any words defined
in the optional word sets and extensions word sets. No standard word provided by a system shall alter the
system state in a way that changes the effect of execution of any other standard word except as provided
in this standard. A system may contain non-standard extensions, provided that they are consistent with the
requirements of this standard.
The implementation of a system may use words and techniques outside the scope of this standard.
A system need not provide all words in executable form. The implementation may provide definitions,
including definitions of words in the Core word set, in source form only. If so, the mechanism for adding
the definitions to the dictionary is implementation defined.
A program that requires a system to provide words or techniques not defined in this standard has an envi-
ronmental dependency.
No data-type checking is required of a system. An ambiguous condition exists if an incorrectly typed data
object is encountered.
Table 3.1 summarizes the data types used throughout this standard. Multiple instances of the same type in
the description of a definition are suffixed with a sequence digit subscript to distinguish them.
Some of the data types are subtypes of other data types. A data type i is a subtype of type j if and only if
the members of i are a subset of the members of j. The following list represents the subtype relationships
using the phrase “i ⇒ j” to denote “i is a subtype of j”. The subtype relationship is transitive; if i ⇒ j and j
⇒ k then i ⇒ k:
+n ⇒ u ⇒ x;
+n ⇒ n ⇒ x;
char ⇒ +n;
a-addr ⇒ c-addr ⇒ addr ⇒ u;
flag ⇒ x;
xt ⇒ x;
ior ⇒ n ⇒ x;
+d ⇒ d ⇒ xd;
+d ⇒ ud ⇒ xd.
Any Forth definition that accepts an argument of type i shall also accept an argument that is a subtype of i.
22
Forth 2012 3. Usage requirements
23
3. Usage requirements Forth 2012
The characters provided by a system shall include the graphic characters {32 . . . 126}, which represent
graphic forms as shown in table 3.2.
A graphic character is one that is normally displayed (e.g., A, #, &, 6). These values and graphics, shown
in table 3.2, are taken directly from ANS X3.4-1974 (ASCII) and ISO 646-1983, International Reference
Version (IRV). The graphic forms of characters outside the hex range {20 . . . 7E} are implementation
defined. Programs that use the graphic hex 24 (the currency sign) have an environmental dependency.
The graphic representation of characters is not restricted to particular type fonts or styles. The graphics
here are examples.
All non-graphic characters included in the implementation-defined character set are defined in this standard
as control characters. In particular, the characters {0 . . . 31}, which could be included in the implement-
ation-defined character set, are control characters.
Programs that require the ability to send or receive control characters have an environmental dependency.
A primitive character (pchar) is a character with no restrictions on its contents. Unless otherwise stated, a
“character” refers to a primitive character.
24
Forth 2012 3. Usage requirements
Cells shall be at least one address unit wide and contain at least sixteen bits. The size of a cell shall be an
integral multiple of the size of a character. Data-stack elements, return-stack elements, addresses, execution
tokens, flags, and integers are one cell wide.
3.1.3.1 Flags
Flags may have one of two logical states, true or false. Programs that use flags as arithmetic operands have
an environmental dependency. A true flag returned by a standard word shall be a single-cell value with all
bits set. A false flag returned by a standard word shall be a single-cell value with all bits clear.
3.1.3.2 Integers
The implementation-defined range of signed integers shall include {-32767 . . . +32767}. The implement-
ation-defined range of non-negative integers shall include {0 . . . 32767}. The implementation-defined
range of unsigned integers shall include {0 . . . 65535}.
3.1.3.3 Addresses
An address identifies a location in data space with a size of one address unit, which a program may fetch
from or store into except for the restrictions established in this standard. The size of an address unit
is specified in bits. Each distinct address value identifies exactly one such storage element. See 3.3.3
Data space.
The set of character-aligned addresses, addresses at which a character can be accessed, is an implement-
ation-defined subset of all addresses. Adding the size of a character to a character-aligned address shall
produce another character-aligned address.
The set of aligned addresses is an implementation-defined subset of character-aligned addresses. Adding
the size of a cell to an aligned address shall produce another aligned address.
A counted string in memory is identified by the address (c-addr) of its length character.
The length character of a counted string shall contain a binary representation of the number of data char-
acters, between zero and the implementation-defined maximum length for a counted string. The maximum
length of a counted string shall be at least 255.
Different definitions may have the same execution token if the definitions are equivalent.
A value of zero indicates that the operation completed successfully; other values are in the range {-4095
. . . -1} and represent a valid THROW code.
The meanings of values in the range {-255 . . . -1} are defined by table 9.1 THROW code assignments.
Values in the range {-4095 . . . -256} and their meanings are implementation defined.
A word that returns an ior will not THROW that ior as an exception, but indicates the exception through the
ior. This allows a program to take appropriate actions, which may include throwing the exception.
25
3. Usage requirements Forth 2012
On the stack, the cell containing the most significant part of a double-cell integer shall be above the cell
containing the least significant part.
The implementation-defined range of double-cell signed integers shall include {-2147483647 . . .
+2147483647}.
The implementation-defined range of double-cell non-negative integers shall include {0 . . . 2147483647}.
The implementation-defined range of double-cell unsigned integers shall include {0 . . . 4294967295}.
Placing the single-cell integer zero on the stack above a single-cell unsigned integer produces a double-cell
unsigned integer with the same value. See 3.2.1.1 Internal number representation.
3.1.4.2 Character strings
A string is specified by a cell pair (c-addr u) representing its starting address and length in characters.
These data types denote zero or more items on the control-flow stack (see 3.2.3.2). The possible presence
of such items on the data stack means that any items already there shall be unavailable to a program until
the control-flow-stack items are consumed.
The implementation-dependent data generated upon beginning to compile a definition and consumed at its
close is represented by the symbol colon-sys throughout this standard.
The implementation-dependent data generated upon beginning to compile a do-loop structure such as DO
. . . LOOP and consumed at its close is represented by the symbol do-sys throughout this standard.
The implementation-dependent data generated upon beginning to compile a CASE . . . ENDCASE structure
and consumed at its close is represented by the symbol case-sys throughout this standard.
The implementation-dependent data generated upon beginning to compile an OF . . . ENDOF structure and
consumed at its close is represented by the symbol of-sys throughout this standard.
The implementation-dependent data generated and consumed by executing the other standard control-flow
words is represented by the symbols orig and dest throughout this standard.
3.1.5.2 System-execution types
These data types denote zero or more items on the return stack. Their possible presence means that any
items already on the return stack shall be unavailable to a program until the system-execution items are
consumed.
26
Forth 2012 3. Usage requirements
The implementation-dependent data generated upon beginning to execute a definition and consumed upon
exiting it is represented by the symbol nest-sys throughout this standard.
The implementation-dependent loop-control parameters used to control the execution of do-loops are repre-
sented by the symbol loop-sys throughout this standard. Loop-control parameters shall be available inside
the do-loop for words that use or change these parameters, words such as I, J, LEAVE and UNLOOP.
This standard allows one’s complement, two’s complement, or sign-magnitude number representations and
arithmetic. Arithmetic zero is represented as the value of a single cell with all bits clear.
The representation of a number as a compiled literal or in memory is implementation dependent.
Numbers shall be represented externally by using characters from the standard character set. Conversion
between the internal and external forms of a digit shall behave as follows:
The value in BASE is the radix for number conversion. A digit has a value ranging from zero to one less than
the contents of BASE. The digit with the value zero corresponds to the character “0”. This representation
of digits proceeds through the character set to the decimal value nine corresponding to the character “9”.
For digits beginning with the decimal value ten the graphic characters beginning with the character “A” are
used. This correspondence continues up to and including the digit with the decimal value thirty-five which
is represented by the character “Z”. The characters “a” though to “z” should be treated the same as “A”
though “Z”, with “a” having the value ten and “z” the value thirty-five. The conversion of digits outside
this range is implementation defined.
Free-field number display uses the characters described in digit conversion, without leading zeros, in a field
the exact size of the converted string plus a trailing space. If a number is zero, the least significant digit is
not considered a leading zero. If the number is negative, a leading minus sign is displayed.
Number display may use the pictured numeric output string buffer to hold partially converted strings (see
3.3.3.6 Other transient regions).
3.2.2 Arithmetic
3.2.2.1 Integer division
Division produces a quotient q and a remainder r by dividing operand a by operand b. Division operations
return q, r, or both. The identity b × q + r = a shall hold for all a and b.
When unsigned integers are divided and the remainder is not zero, q is the largest integer less than the true
quotient.
27
3. Usage requirements Forth 2012
When signed integers are divided, the remainder is not zero, and a and b have the same sign, q is the largest
integer less than the true quotient. If only one operand is negative, whether q is rounded toward negative
infinity (floored division) or rounded towards zero (symmetric division) is implementation defined.
Floored division is integer division in which the remainder carries the sign of the divisor or is zero, and the
quotient is rounded to its arithmetic floor. Symmetric division is integer division in which the remainder
carries the sign of the dividend or is zero and the quotient is the mathematical quotient “rounded towards
zero” or “truncated”. Examples of each are shown in tables 3.3 and 3.4.
In cases where the operands differ in sign and the rounding direction matters, a program shall either include
code generating the desired form of division, not relying on the implementation-defined default result, or
have an environmental dependency on the desired rounding direction.
Table 3.3: Floored Division Example Table 3.4: Symmetric Division Example
Dividend Divisor Remainder Quotient Dividend Divisor Remainder Quotient
10 7 3 1 10 7 3 1
-10 7 4 -2 -10 7 -3 -1
10 -7 -4 -2 10 -7 3 -1
-10 -7 -3 1 -10 -7 -3 1
In all integer arithmetic operations, both overflow and underflow shall be ignored. The value returned when
either overflow or underflow occurs is implementation defined.
3.2.3 Stacks
3.2.3.1 Data stack
The control-flow stack is a last-in, first out list whose elements define the permissible matchings of control-
flow words and the restrictions imposed on data-stack usage during the compilation of control structures.
The elements of the control-flow stack are system-compilation data types.
The control-flow stack may, but need not, physically exist in an implementation. If it does exist, it may be,
but need not be, implemented using the data stack. The format of the control-flow stack is implementation
defined.
3.2.3.3 Return stack
Items on the return stack shall consist of one or more cells. A system may use the return stack in an
implementation-dependent manner during the compilation of definitions, during the execution of do-loops,
and for storing run-time nesting information.
A program may use the return stack for temporary storage during the execution of a definition subject to
the following restrictions:
28
Forth 2012 3. Usage requirements
– A program shall not access values on the return stack (using R@, R>, 2R@, 2R> or NR>) that it did
not place there using >R, 2>R or N>R;
– A program shall not access from within a do-loop values placed on the return stack before the loop
was entered;
– All values placed on the return stack within a do-loop shall be removed before I, J, LOOP, +LOOP,
UNLOOP, or LEAVE is executed;
– All values placed on the return stack within a definition shall be removed before the definition is
terminated or before EXIT is executed.
29
3. Usage requirements Forth 2012
The structure of a word list is implementation dependent. When duplicate names exist in a word list, the
latest-defined duplicate shall be the one found during a search for the name.
3.3.1.2 Definition names
Definition names shall contain {1 . . . 31} characters. A system may allow or prohibit the creation of
definition names containing non-standard characters. A system may allow the creation of definition names
longer than 31 characters. Programs with definition names longer than 31 characters have an environmental
dependency.
Programs that use lower case for standard definition names or depend on the case-sensitivity properties of
a system have an environmental dependency.
A program shall not create definition names containing non-graphic characters.
30
Forth 2012 3. Usage requirements
Most addresses are cell aligned (indicated by a-addr) or character aligned (c-addr). ALIGNED, CHAR+,
and arithmetic operations can alter the alignment state of an address on the stack. CHAR+ applied to an
aligned address returns a character-aligned address that can only be used to access characters. Applying
CHAR+ to a character-aligned address produces the succeeding character-aligned address. Adding or sub-
tracting an arbitrary number to an address can produce an unaligned address that shall not be used to fetch
31
3. Usage requirements Forth 2012
or store anything. The only way to find the next aligned address is with ALIGNED. An ambiguous condi-
tion exists when memory is accessed using an address that is not aligned according to the requirements for
the accessed type.
The definitions of 6.1.1000 CREATE and 6.1.2410 VARIABLE require that the definitions created by them
return aligned addresses.
After definitions are compiled or the word ALIGN is executed the data-space pointer is guaranteed to be
aligned.
A system guarantees that a region of data space allocated using ALLOT, , (comma), C, (c-comma), and
ALIGN shall be contiguous with the last region allocated with one of the above words, unless the restric-
tions in the following paragraphs apply. The data-space pointer HERE always identifies the beginning of the
next data-space region to be allocated. As successive allocations are made, the data-space pointer increases.
A program may perform address arithmetic within contiguously allocated regions. The last region of data
space allocated using the above operators may be released by allocating a corresponding negatively-sized
region using ALLOT, subject to the restrictions of the following paragraphs.
CREATE establishes the beginning of a contiguous region of data space, whose starting address is returned
by the CREATEd definition. This region is terminated by compiling the next definition.
Since an implementation is free to allocate data space for use by code, the above operators need not pro-
duce contiguous regions of data space if definitions are added to or removed from the dictionary between
allocations. An ambiguous condition exists if deallocated memory contains definitions.
3.3.3.3 Variables
The region allocated for a variable may be non-contiguous with regions subsequently allocated with
, (comma) or ALLOT. For example, in:
VARIABLE X 1 CELLS ALLOT
the region X and the region ALLOTted could be non-contiguous.
Some system-provided variables, such as STATE, are restricted to read-only access.
The text-literal regions, specified by strings compiled with S", S\" and C", may be read-only.
A program shall not store into the text-literal regions created by S", S\" and C" nor into any read-only
system variable or read-only transient regions.
3.3.3.5 Input buffers
The address, length, and content of the input buffer may be transient. A program shall not write into the
input buffer. In the absence of any optional word sets providing alternative input sources, the input buffer
is either the terminal-input buffer, used by QUIT to hold one line from the user input device, or a buffer
specified by EVALUATE. In all cases, SOURCE returns the beginning address and length in characters of
the current input buffer.
32
Forth 2012 3. Usage requirements
The data space regions identified by PAD, WORD, and #> (the pictured numeric output string buffer) may
be transient. Their addresses and contents may become invalid after:
– a definition is created via a defining word;
– definitions are compiled with : or :NONAME;
– data space is allocated using ALLOT, , (comma), C, (c-comma), or ALIGN.
The previous contents of the regions identified by WORD and #> may be invalid after each use of these
words. Further, the regions returned by WORD and #> may overlap in memory. Consequently, use of one
of these words can corrupt a region returned earlier by a different word. The other words that construct
pictured numeric output strings (<#, #, #S, HOLD, HOLDS, XHOLD) may also modify the contents of
these regions. Words that display numbers may be implemented using pictured numeric output words.
Consequently, . (dot), .R, .S, ?, D., D.R, U., U.R could also corrupt the regions.
The size of the scratch area whose address is returned by PAD shall be at least 84 characters. The contents
of the region addressed by PAD are intended to be under the complete control of the user: no words defined
in this standard place anything in the region, although changing data-space allocations as described in
3.3.3.2 Contiguous regions may change the address returned by PAD. Non-standard words provided by an
implementation may use PAD, but such use shall be documented.
The size of the region identified by WORD shall be at least 33 characters.
The size of the pictured numeric output string buffer shall be at least (2 × n) + 2 characters, where n is the
number of bits in a cell. Programs that consider it a fixed area with unchanging access parameters have an
environmental dependency.
33
3. Usage requirements Forth 2012
Such interactive systems usually furnish a “prompt” indicating that they have accepted a user request and
acted on it. The implementation-defined Forth prompt should contain the word “OK” in some combination
of upper or lower case.
Text interpretation (see 6.1.1360 EVALUATE and 6.1.2050 QUIT) shall repeat the following steps until
either the parse area is empty or an ambiguous condition exists:
a) Skip leading spaces and parse a name (see 3.4.1);
b) Search the dictionary name space (see 3.4.2). If a definition name matching the string is found:
1) if interpreting, perform the interpretation semantics of the definition (see 3.4.3.2), and continue
at a).
2) if compiling, perform the compilation semantics of the definition (see 3.4.3.3), and continue at
a).
c) If a definition name matching the string is not found, attempt to convert the string to a number (see
3.4.1.3). If successful:
1) if interpreting, place the number on the data stack, and continue at a);
2) if compiling, compile code that when executed will place the number on the stack (see 6.1.1780
LITERAL), and continue at a);
d) If unsuccessful, an ambiguous condition exists (see 3.4.4).
3.4.1 Parsing
Unless otherwise noted, the number of characters parsed may be from zero to the implementation-defined
maximum length of a counted string.
If the parse area is empty, i.e., when the number in >IN is equal to the length of the input buffer, or contains
no characters other than delimiters, the selected string is empty. Otherwise, the selected string begins with
the next character in the parse area, which is the character indexed by the contents of >IN. An ambiguous
condition exists if the number in >IN is greater than the size of the input buffer.
If delimiter characters are present in the parse area after the beginning of the selected string, the string
continues up to and including the character just before the first such delimiter, and the number in >IN is
changed to index immediately past that delimiter, thus removing the parsed characters and the delimiter
from the parse area. Otherwise, the string continues up to and including the last character in the parse area,
and the number in >IN is changed to the length of the input buffer, thus emptying the parse area.
Parsing may change the contents of >IN, but shall not affect the contents of the input buffer. Specifically, if
the value in >IN is saved before starting the parse, resetting >IN to that value immediately after the parse
shall restore the parse area without loss of data.
3.4.1.1 Delimiters
If the delimiter is the space character, hex 20 (BL), control characters may be treated as delimiters. The
set of conditions, if any, under which a “space” delimiter matches control characters is implementation
defined.
To skip leading delimiters is to pass by zero or more contiguous delimiters in the parse area before parsing.
34
Forth 2012 3. Usage requirements
3.4.1.2 Syntax
Forth has a simple, operator-ordered syntax. The phrase A B C returns values as if A were executed
first, then B and finally C. Words that cause deviations from this linear flow of control are called control-
flow words. Combinations of control-flow words whose stack effects are compatible form control-flow
structures. Examples of typical use are given for each control-flow word in Annex A.
Forth syntax is extensible; for example, new control-flow words can be defined in terms of existing ones.
This standard does not require a syntax or program-construct checker.
When converting input numbers, the text interpreter shall recognize integer numbers in the form hanynumi.
hanynumi := { hBASEnumi | hdecnumi | hhexnumi | hbinnumi | hcnumi }
hBASEnumi := [-]hbdigitihbdigiti*
hdecnumi := #[-]hdecdigitihdecdigiti*
hhexnumi := $[-]hhexdigitihhexdigiti*
hbinnumi := %[-]hbindigitihbindigiti*
hcnumi := ’hchari’
hbindigiti := { 0 | 1 }
hdecdigiti := { 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 }
hhexdigiti := { hdecdigiti | a | b | c | d | e | f | A | B | C | D | E | F }
hbdigiti represents a digit according to the value of BASE (see 3.2.1.2 Digit conversion). For hhexdigiti,
the digits a. . . f have the values 10. . . 15. hchari represents any printable character.
The matching of upper- and lower-case letters with alphabetic characters in character set extensions such
as accented international characters is implementation defined.
A system shall be capable of finding the definition names defined by this standard when they are spelled
with upper-case letters.
35
3. Usage requirements Forth 2012
3.4.3 Semantics
The semantics of a Forth definition are implemented by machine code or a sequence of execution tokens
or other representations. They are largely specified by the stack notation in the glossary entries, which
shows what values shall be consumed and produced. The prose in each glossary entry further specifies the
definition’s behavior.
Each Forth definition may have several behaviors, described in the following sections. The terms “initia-
tion semantics” and “run-time semantics” refer to definition fragments, and have meaning only within the
individual glossary entries where they appear.
3.4.3.1 Execution semantics
The execution semantics of each Forth definition are specified in an “Execution:” section of its glossary
entry. When a definition has only one specified behavior, the label is omitted.
Execution may occur implicitly, when the definition into which it has been compiled is executed, or explic-
itly, when its execution token is passed to EXECUTE. The execution semantics of a syntactically correct
definition under conditions other than those specified in this standard are implementation dependent.
Glossary entries for defining words include the execution semantics for the new definition in a “name
Execution:” section.
Unless otherwise specified in an “Interpretation:” section of the glossary entry, the interpretation semantics
of a Forth definition are its execution semantics.
A system shall be capable of executing, in interpretation state, all of the definitions from the Core word
set and any definitions included from the optional word sets or word set extensions whose interpretation
semantics are defined by this standard.
A system shall be capable of executing, in interpretation state, any new definitions created in accordance
with 3 Usage requirements.
3.4.3.3 Compilation semantics
Unless otherwise specified in a “Compilation:” section of the glossary entry, the compilation semantics
of a Forth definition shall be to append its execution semantics to the execution semantics of the current
definition.
36
Forth 2012 3. Usage requirements
3.4.5 Compilation
A program shall not attempt to nest compilation of definitions.
During the compilation of the current definition, a program shall not execute any defining word, :NONAME,
or any definition that allocates dictionary data space. The compilation of the current definition may be
suspended using [ (left-bracket) and resumed using ] (right-bracket). While the compilation of the current
definition is suspended, a program shall not execute any defining word, :NONAME, or any definition that
allocates dictionary data space.
37
4. Documentation requirements Forth 2012
4 Documentation requirements
When it is impossible or infeasible for a system or program to define a particular behavior itself, it is
permissible to state that the behavior is unspecifiable and to explain the circumstances and reasons why
this is so.
38
Forth 2012 4. Documentation requirements
– ranges for n, +n, u, d, +d, and ud (3.1.3 Single-cell types, 3.1.4 Cell-pair types);
– read-only data-space regions (3.3.3 Data space);
– size of buffer at 6.1.2450 WORD (3.3.3.6 Other transient regions);
– size of one cell in address units (3.1.3 Single-cell types);
– size of one character in address units (3.1.2 Character types);
– size of the keyboard terminal input buffer (3.3.3.5 Input buffers);
– size of the pictured numeric output string buffer (3.3.3.6 Other transient regions);
– size of the scratch area whose address is returned by 6.2.2000 PAD
(3.3.3.6 Other transient regions);
– system case-sensitivity characteristics (3.4.2 Finding definition names);
– system prompt (3.3 The Forth dictionary, 6.1.2050 QUIT);
– type of division rounding (3.2.2.1 Integer division, 6.1.0100 */, 6.1.0110 */MOD, 6.1.0230 /,
6.1.0240 /MOD, 6.1.1890 MOD);
– values of 6.1.2250 STATE when true;
– values returned after arithmetic overflow (3.2.2.2 Other integer operations);
– whether the current definition can be found after 6.1.1250 DOES> (6.1.0450 :).
39
4. Documentation requirements Forth 2012
40
Forth 2012 4. Documentation requirements
– access to a deferred word, a word defined by 6.2.1173 DEFER, which was not defined by 6.2.1173
DEFER.
– 6.1.2033 POSTPONE, 6.2.2530 [COMPILE], 6.1.2510 [’] or 6.1.0070 ’ applied to 6.2.0698
ACTION-OF or 6.2.1725 IS.
– \x is not followed by two hexadecimal characters (6.2.2266 S\").
– a \ is placed before any character, other than those defined in 6.2.2266 S\".
41
4. Documentation requirements Forth 2012
– using definition names of more than 31 characters in length (3.3.1.2 Definition names);
– using the graphic character with a value of hex 24 (3.1.2.1 Graphic characters).
42
Forth 2012 5. Compliance and labeling
43
6. CORE Word Set Forth 2012
6 Glossary
( x a-addr – – )
Store x at a-addr.
See: 3.3.3.1 Address alignment.
( ud1 – – ud2 )
Divide ud1 by the number in BASE giving the quotient ud2 and the remainder n. (n is the
least significant digit of ud1.) Convert n to external form and add the resulting character
to the beginning of the pictured numeric output string. An ambiguous condition exists if
# executes outside of a <# #> delimited number conversion.
See: 6.1.0040 #>, 6.1.0050 #S, 6.1.0490 <#.
( xd – – c-addr u )
Drop xd. Make the pictured numeric output string available as a character string. c-addr
and u specify the resulting character string. A program may replace characters within
the string.
See: 6.1.0030 #, 6.1.0050 #S, 6.1.0490 <#.
( ud1 – – ud2 )
Convert one digit of ud1 according to the rule for #. Continue conversion until the
quotient is zero. ud2 is zero. An ambiguous condition exists if #S executes outside
of a <# #> delimited number conversion.
See: 6.1.0030 #, 6.1.0040 #>, 6.1.0490 <#.
( “hspacesiname” – – xt )
Skip leading space delimiters. Parse name delimited by a space. Find name and return
xt, the execution token for name. An ambiguous condition exists if name is not found.
When interpreting, ’ xyz EXECUTE is equivalent to xyz.
See: 3.4.3.2 Interpretation semantics, 3.4.1 Parsing, A.6.1.0070 ’, A.6.1.2033 POSTPONE,
A.6.1.2510 [’].
( n1 | u1 n2 | u2 – – n3 | u3 )
Multiply n1 | u1 by n2 | u2 giving the product n3 | u3.
( n1 n2 n3 – – n4 )
Multiply n1 by n2 producing the intermediate double-cell result d. Divide d by n3 giv-
ing the single-cell quotient n4. An ambiguous condition exists if n3 is zero or if the
quotient n4 lies outside the range of a signed number. If d and n3 differ in sign, the
implementation-defined result returned will be the same as that returned by either the
phrase >R M* R> FM/MOD SWAP DROP or the phrase >R M* R> SM/REM SWAP DROP.
See: 3.2.2.1 Integer division.
( n1 n2 n3 – – n4 n5 )
Multiply n1 by n2 producing the intermediate double-cell result d. Divide d by n3 produc-
ing the single-cell remainder n4 and the single-cell quotient n5. An ambiguous condition
exists if n3 is zero, or if the quotient n5 lies outside the range of a single-cell signed in-
teger. If d and n3 differ in sign, the implementation-defined result returned will be the
same as that returned by either the phrase >R M* R> FM/MOD or the phrase >R M* R>
SM/REM.
See: 3.2.2.1 Integer division.
( n1 | u1 n2 | u2 – – n3 | u3 )
Add n2 | u2 to n1 | u1, giving the sum n3 | u3.
See: 3.3.3.1 Address alignment.
( n | u a-addr – – )
Add n | u to the single-cell number at a-addr.
See: 3.3.3.1 Address alignment.
( x –– )
Reserve one cell of data space and store x in the cell. If the data-space pointer is aligned
when , begins execution, it will remain aligned when , finishes execution. An ambigu-
ous condition exists if the data-space pointer is not aligned prior to execution of ,.
See: 3.3.3 Data space, 3.3.3.1 Address alignment, A.6.1.0150 ,.
( n1 | u1 n2 | u2 – – n3 | u3 )
Subtract n2 | u2 from n1 | u1, giving the difference n3 | u3.
See: 3.3.3.1 Address alignment.
( n –– )
Display n in free field format.
See: 3.2.1.2 Digit conversion, 3.2.1.3 Free-field number display.
( n1 n2 – – n3 )
Divide n1 by n2, giving the single-cell quotient n3. An ambiguous condition exists if n2
is zero. If n1 and n2 differ in sign, the implementation-defined result returned will be
the same as that returned by either the phrase >R S>D R> FM/MOD SWAP DROP or the
phrase >R S>D R> SM/REM SWAP DROP.
See: 3.2.2.1 Integer division.
( n1 n2 – – n3 n4 )
Divide n1 by n2, giving the single-cell remainder n3 and the single-cell quotient n4. An
ambiguous condition exists if n2 is zero. If n1 and n2 differ in sign, the implementation-
defined result returned will be the same as that returned by either the phrase >R S>D R>
FM/MOD or the phrase >R S>D R> SM/REM.
See: 3.2.2.1 Integer division.
( n – – flag )
flag is true if and only if n is less than zero.
( x – – flag )
flag is true if and only if x is equal to zero.
( n1 | u1 – – n2 | u2 )
Add one (1) to n1 | u1 giving the sum n2 | u2.
( n1 | u1 – – n2 | u2 )
Subtract one (1) from n1 | u1 giving the difference n2 | u2.
( x1 x2 a-addr – – )
Store the cell pair x1 x2 at a-addr, with x2 at a-addr and x1 at the next consecutive cell. It
is equivalent to the sequence SWAP OVER ! CELL+ !.
See: 3.3.3.1 Address alignment.
( x1 – – x2 )
x2 is the result of shifting x1 one bit toward the most-significant bit, filling the vacated
least-significant bit with zero.
( x1 – – x2 )
x2 is the result of shifting x1 one bit toward the least-significant bit, leaving the most-
significant bit unchanged.
( a-addr – – x1 x2 )
Fetch the cell pair x1 x2 stored at a-addr. x2 is stored at a-addr and x1 at the next consec-
utive cell. It is equivalent to the sequence DUP CELL+ @ SWAP @.
See: 3.3.3.1 Address alignment, 6.1.0310 2!.
( x1 x2 – – )
Drop cell pair x1 x2 from the stack.
( x1 x2 – – x1 x2 x1 x2 )
Duplicate cell pair x1 x2.
( x1 x2 x3 x4 – – x1 x2 x3 x4 x1 x2 )
Copy cell pair x1 x2 to the top of the stack.
( x1 x2 x3 x4 – – x3 x4 x1 x2 )
Exchange the top two cell pairs.
( C: “hspacesiname” – – colon-sys )
Skip leading space delimiters. Parse name delimited by a space. Create a definition for
name, called a “colon definition”. Enter compilation state and start the current defini-
tion, producing colon-sys. Append the initiation semantics given below to the current
definition.
The execution semantics of name will be determined by the words compiled into the
body of the definition. The current definition shall not be findable in the dictionary until
it is ended (or until the execution of DOES> in some systems).
Initiation: ( i * x – – i * x ) ( R: – – nest-sys )
Save implementation-dependent information nest-sys about the calling definition. The
stack effects i * x represent arguments to name.
name Execution: ( i * x – – j * x )
Execute the definition name. The stack effects i * x and j * x represent arguments to and
results from name, respectively.
See: 3.4.3.2 Interpretation semantics, 3.4.1 Parsing, 3.4.5 Compilation, 6.1.1250 DOES>,
6.1.2500 [, 6.1.2540 ], 15.6.2.0470 ;CODE, A.6.1.0450 :.
( n1 n2 – – flag )
flag is true if and only if n1 is less than n2.
See: 6.1.2340 U<.
( –– )
Initialize the pictured numeric output conversion process.
See: 6.1.0030 #, 6.1.0040 #>, 6.1.0050 #S.
( x1 x2 – – flag )
flag is true if and only if x1 is bit-for-bit the same as x2.
( n1 n2 – – flag )
flag is true if and only if n1 is greater than n2.
See: 6.2.2350 U>.
( xt – – a-addr )
a-addr is the data-field address corresponding to xt. An ambiguous condition exists if xt
is not for a word defined via CREATE.
See: 3.3.3 Data space, A.6.1.0550 >BODY.
( – – a-addr )
a-addr is the address of a cell containing the offset in characters from the start of the
input buffer to the start of the parse area.
past the end of the string if the string was entirely converted. u2 is the number of uncon-
verted characters in the string. An ambiguous condition exists if ud2 overflows during
the conversion.
See: 3.2.1.2 Digit conversion.
( x –– 0 | x x )
Duplicate x if it is non-zero.
( a-addr – – x )
x is the value stored at a-addr.
See: 3.3.3.1 Address alignment.
( i * x – – ) ( R: j * x – – )
Empty the data stack and perform the function of QUIT, which includes emptying the
return stack, without displaying a message.
See: 9.6.2.0670 ABORT.
Run-time: ( i * x x1 – – | i * x ) ( R: j * x – – | j * x )
Remove x1 from the stack. If any bit of x1 is not zero, display ccc and perform an
implementation-defined abort sequence that includes the function of ABORT.
See: 3.4.1 Parsing, 9.6.2.0680 ABORT", A.6.1.0680 ABORT".
( n –– u )
u is the absolute value of n.
( –– )
If the data-space pointer is not aligned, reserve enough space to align it.
See: 3.3.3 Data space, 3.3.3.1 Address alignment, A.6.1.0705 ALIGN.
( addr – – a-addr )
a-addr is the first aligned address greater than or equal to addr.
See: 3.3.3.1 Address alignment, 6.1.0705 ALIGN.
( n –– )
If n is greater than zero, reserve n address units of data space. If n is less than zero,
release | n | address units of data space. If n is zero, leave the data-space pointer
unchanged.
If the data-space pointer is aligned and n is a multiple of the size of a cell when ALLOT
begins execution, it will remain aligned when ALLOT finishes execution.
If the data-space pointer is character aligned and n is a multiple of the size of a character
when ALLOT begins execution, it will remain character aligned when ALLOT finishes
execution.
See: 3.3.3 Data space.
( x1 x2 – – x3 )
x3 is the bit-by-bit logical “and” of x1 with x2.
( – – a-addr )
a-addr is the address of a cell containing the current number-conversion radix {{2...36}}.
( – – char )
char is the character value for a space.
See: A.6.1.0770 BL.
( char c-addr – – )
Store char at c-addr. When character size is smaller than cell size, only the number of
low-order bits corresponding to character size are transferred.
See: 3.3.3.1 Address alignment.
( char – – )
Reserve space for one character in the data space and store char in the space. If the data-
space pointer is character aligned when C, begins execution, it will remain character
aligned when C, finishes execution. An ambiguous condition exists if the data-space
pointer is not character-aligned prior to execution of C,.
See: 3.3.3 Data space, 3.3.3.1 Address alignment.
( c-addr – – char )
Fetch the character stored at c-addr. When the cell size is greater than character size, the
unused high-order bits are all zeroes.
See: 3.3.3.1 Address alignment.
( a-addr1 – – a-addr2 )
Add the size in address units of a cell to a-addr1, giving a-addr2.
See: 3.3.3.1 Address alignment, A.6.1.0880 CELL+.
( n1 – – n2 )
n2 is the size in address units of n1 cells.
See: A.6.1.0880 CELL+, A.6.1.0890 CELLS.
( “hspacesiname” – – char )
Skip leading space delimiters. Parse name delimited by a space. Put the value of its first
character onto the stack.
See: 3.4.1 Parsing, 6.1.2520 [CHAR], A.6.1.0895 CHAR.
( c-addr1 – – c-addr2 )
Add the size in address units of a character to c-addr1, giving c-addr2.
See: 3.3.3.1 Address alignment.
( n1 – – n2 )
n2 is the size in address units of n1 characters.
( x “hspacesiname” – – )
Skip leading space delimiters. Parse name delimited by a space. Create a definition for
name with the execution semantics defined below.
name is referred to as a “constant”.
name Execution: ( – – x )
Place x on the stack.
See: 3.4.1 Parsing, A.6.1.0950 CONSTANT.
( c-addr1 – – c-addr2 u )
Return the character string specification for the counted string stored at c-addr1. c-addr2
is the address of the first character after c-addr1. u is the contents of the character at
c-addr1, which is the length in characters of the string at c-addr2.
( –– )
Cause subsequent output to appear at the beginning of the next line.
( “hspacesiname” – – )
Skip leading space delimiters. Parse name delimited by a space. Create a definition
for name with the execution semantics defined below. If the data-space pointer is not
aligned, reserve enough data space to align it. The new data-space pointer defines name’s
data field. CREATE does not allocate data space in name’s data field.
name Execution: ( – – a-addr )
a-addr is the address of name’s data field. The execution semantics of name may be
extended by using DOES>.
See: 3.3.3 Data space, 6.1.1250 DOES>, A.6.1.1000 CREATE.
( –– )
Set the numeric conversion radix to ten (decimal).
( – – +n )
+n is the number of single-cell values contained in the data stack before +n was placed
on the stack.
6.1.1240 DO CORE
Set up loop control parameters with index n2 | u2 and limit n1 | u1. An ambiguous
condition exists if n1 | u1 and n2 | u2 are not both the same type. Anything already on the
return stack becomes unavailable until the loop-control parameters are discarded.
See: 3.2.3.2 Control-flow stack, 6.1.0140 +LOOP, 6.1.1800 LOOP, A.6.1.1240 DO.
( x –– )
Remove x from the stack.
( x –– x x )
Duplicate x.
( x –– )
If x is a graphic character in the implementation-defined character set, display x. The
effect of EMIT for all other values of x is implementation-defined.
When passed a character whose character-defining bits have a value between hex 20
and 7E inclusive, the corresponding standard character, specified by 3.1.2.1 Graphic
characters, is displayed. Because different output devices can respond differently to
control characters, programs that use control characters to perform specific functions
have an environmental dependency. Each EMIT deals with only one character.
See: 6.1.2310 TYPE.
( i * x c-addr u – – j * x )
Save the current input source specification. Store minus-one (-1) in SOURCE-ID if it
is present. Make the string described by c-addr and u both the input source and input
buffer, set >IN to zero, and interpret. When the parse area is empty, restore the prior
input source specification. Other stack effects are due to the words EVALUATEd.
( i * x xt – – j * x )
Remove xt from the stack and perform the semantics identified by it. Other stack effects
are due to the word EXECUTEd.
See: 6.1.0070 ’, 6.1.2510 [’].
( c-addr u char – – )
If u is greater than zero, store char in each of u consecutive characters of memory begin-
ning at c-addr.
( c-addr – – c-addr 0 | xt 1 | xt -1 )
Find the definition named in the counted string at c-addr. If the definition is not found,
return c-addr and zero. If the definition is found, return its execution token xt. If the
definition is immediate, also return one (1), otherwise also return minus-one (-1). For
a given string, the values returned by FIND while compiling may differ from those re-
turned while not compiling.
See: 3.4.2 Finding definition names, A.6.1.0070 ’, A.6.1.1550 FIND,
A.6.1.2033 POSTPONE, A.6.1.2510 [’].
( d1 n1 – – n2 n3 )
Divide d1 by n1, giving the floored quotient n3 and the remainder n2. Input and output
stack arguments are signed. An ambiguous condition exists if n1 is zero or if the quotient
lies outside the range of a single-cell signed integer.
See: 3.2.2.1 Integer division, 6.1.2214 SM/REM, 6.1.2370 UM/MOD, A.6.1.1561 FM/MOD.
( – – addr )
addr is the data-space pointer.
See: 3.3.3.2 Contiguous regions.
( char – – )
Add char to the beginning of the pictured numeric output string. An ambiguous condi-
tion exists if HOLD executes outside of a <# #> delimited number conversion.
6.1.1680 I CORE
6.1.1700 IF CORE
( –– )
Make the most recent definition an immediate word. An ambiguous condition exists if
the most recent definition does not have a name or if it was defined as a SYNONYM.
See: 15.6.2.2264 SYNONYM A.6.1.1710 IMMEDIATE.
( x1 – – x2 )
Invert all bits of x1, giving its logical inverse x2.
See: 6.1.1910 NEGATE, 6.1.0270 0=, A.6.1.1720 INVERT.
6.1.1730 J CORE
( – – char )
Receive one character char, a member of the implementation-defined character set. Key-
board events that do not correspond to such characters are discarded until a valid charac-
ter is received, and those events are subsequently unavailable.
All standard characters can be received. Characters received by KEY are not displayed.
Any standard character returned by KEY has the numeric value specified in 3.1.2.1
Graphic characters. Programs that require the ability to receive control characters have
an environmental dependency.
See: 10.6.2.1305 EKEY, 10.6.2.1307 EKEY?, 10.6.1.1755 KEY?, A.6.1.1750 KEY.
( x1 u – – x2 )
Perform a logical left shift of u bit-places on x1, giving x2. Put zeroes into the least
significant bits vacated by the shift. An ambiguous condition exists if u is greater than
or equal to the number of bits in a cell.
( n1 n2 – – d )
d is the signed product of n1 times n2.
See: A.6.1.1810 M*.
( n1 n2 – – n3 )
n3 is the greater of n1 and n2.
( n1 n2 – – n3 )
n3 is the lesser of n1 and n2.
( n1 n2 – – n3 )
Divide n1 by n2, giving the single-cell remainder n3. An ambiguous condition exists if n2
is zero. If n1 and n2 differ in sign, the implementation-defined result returned will be the
same as that returned by either the phrase >R S>D R> FM/MOD DROP or the phrase >R
S>D R> SM/REM DROP.
See: 3.2.2.1 Integer division.
( addr1 addr2 u – – )
If u is greater than zero, copy the contents of u consecutive address units at addr1 to the
u consecutive address units at addr2. After MOVE completes, the u consecutive address
units at addr2 contain exactly what the u consecutive address units at addr1 contained
before the move.
See: 17.6.1.0910 CMOVE, 17.6.1.0920 CMOVE>, A.6.1.1900 MOVE.
( n1 – – n2 )
Negate n1, giving its arithmetic inverse n2.
See: 6.1.1720 INVERT, 6.1.0270 0=.
6.1.1980 OR CORE
( x1 x2 – – x3 )
x3 is the bit-by-bit inclusive-or of x1 with x2.
( x1 x2 – – x1 x2 x1 )
Place a copy of x1 on top of the stack.
( – – ) ( R: i * x – – )
Empty the return stack, store zero in SOURCE-ID if it is present, make the user input
device the input source, and enter interpretation state. Do not display a message. Repeat
the following:
– Accept a line from the input source into the input buffer, set >IN to zero, and
interpret.
– Display the implementation-defined system prompt if in interpretation state, all
processing has been completed, and no ambiguous condition exists.
See: 3.4 The Forth text interpreter.
( x1 x2 x3 – – x2 x3 x1 )
Rotate the top three stack entries.
( x1 u – – x2 )
Perform a logical right shift of u bit-places on x1, giving x2. Put zeroes into the most
significant bits vacated by the shift. An ambiguous condition exists if u is greater than
or equal to the number of bits in a cell.
( n –– d )
Convert the number n to the double-cell number d with the same numerical value.
( n –– )
If n is negative, add a minus sign to the beginning of the pictured numeric output string.
An ambiguous condition exists if SIGN executes outside of a <# #> delimited number
conversion.
( d1 n1 – – n2 n3 )
Divide d1 by n1, giving the symmetric quotient n3 and the remainder n2. Input and output
stack arguments are signed. An ambiguous condition exists if n1 is zero or if the quotient
lies outside the range of a single-cell signed integer.
See: 3.2.2.1 Integer division, 6.1.1561 FM/MOD, 6.1.2370 UM/MOD, A.6.1.2214 SM/REM.
( – – c-addr u )
c-addr is the address of, and u is the number of characters in, the input buffer.
See: A.6.1.2216 SOURCE.
( –– )
Display one space.
( n –– )
If n is greater than zero, display n spaces.
( – – a-addr )
a-addr is the address of a cell containing the compilation-state flag. STATE is true
when in compilation state, false otherwise. The true value in STATE is non-zero, but is
otherwise implementation-defined. Only the following standard words alter the value in
STATE: : (colon), ; (semicolon), ABORT, QUIT, :NONAME, [ (left-bracket), ] (right-
bracket).
Note: A program shall not directly alter the contents of STATE.
See: 3.4 The Forth text interpreter, 6.1.0450 :, 6.1.0460 ; 6.1.0670 ABORT, 6.1.2050
QUIT, 6.1.2500 [, 6.1.2540 ], 6.2.0455 :NONAME, 15.6.2.2250 STATE, A.6.1.2250
STATE.
( x1 x2 – – x2 x1 )
Exchange the top two stack items.
( c-addr u – – )
If u is greater than zero, display the character string specified by c-addr and u.
When passed a character in a character string whose character-defining bits have a value
between hex 20 and 7E inclusive, the corresponding standard character, specified by
3.1.2.1 Graphic characters, is displayed. Because different output devices can respond
differently to control characters, programs that use control characters to perform specific
functions have an environmental dependency.
See: 6.1.1320 EMIT.
( u –– )
Display u in free field format.
( u1 u2 – – flag )
flag is true if and only if u1 is less than u2.
See: 6.1.0480 <.
( u1 u2 – – ud )
Multiply u1 by u2, giving the unsigned double-cell product ud. All values and arithmetic
are unsigned.
( ud u1 – – u2 u3 )
Divide ud by u1, giving the quotient u3 and the remainder u2. All values and arithmetic
are unsigned. An ambiguous condition exists if u1 is zero or if the quotient lies outside
the range of a single-cell unsigned integer.
See: 3.2.2.1 Integer division, 6.1.1561 FM/MOD, 6.1.2214 SM/REM.
( “hspacesiname” – – )
Skip leading space delimiters. Parse name delimited by a space. Create a definition for
name with the execution semantics defined below. Reserve one cell of data space at an
aligned address.
name is referred to as a “variable”.
name Execution: ( – – a-addr )
a-addr is the address of the reserved cell. A program is responsible for initializing the
contents of the reserved cell.
See: 3.4.1 Parsing, A.6.1.2410 VARIABLE.
( x1 x2 – – x3 )
x3 is the bit-by-bit exclusive-or of x1 with x2.
( –– )
Enter compilation state.
See: 3.4 The Forth text interpreter, 3.4.5 Compilation, 6.1.2500 [, A.6.1.2540 ].
( n1 n2 – – )
Display n1 right aligned in a field n2 characters wide. If the number of characters required
to display n1 is greater than n2, all digits are displayed with no leading spaces in a field
as wide as necessary.
See: A.6.2.0210 .R.
( x – – flag )
flag is true if and only if x is not equal to zero.
( n – – flag )
flag is true if and only if n is greater than zero.
( C: – – colon-sys ) ( S: – – xt )
Create an execution token xt, enter compilation state and start the current definition, pro-
ducing colon-sys. Append the initiation semantics given below to the current definition.
The execution semantics of xt will be determined by the words compiled into the body
of the definition. This definition can be executed later by using xt EXECUTE.
If the control-flow stack is implemented using the data stack, colon-sys shall be the
topmost item on the data stack. See 3.2.3.2 Control-flow stack.
Initiation: ( i * x – – i * x ) ( R: – – nest-sys )
Save implementation-dependent information nest-sys about the calling definition. The
stack effects i * x represent arguments to xt.
xt Execution: ( i * x – – j * x )
Execute the definition specified by xt. The stack effects i * x and j * x represent arguments
to and results from xt, respectively.
See: A.6.2.0455 :NONAME.
( x1 x2 – – flag )
flag is true if and only if x1 is not bit-for-bit the same as x2.
Interpretation: ( “hspacesiname” – – xt )
Skip leading spaces and parse name delimited by a space. xt is the execution token
that name is set to execute. An ambiguous condition exists if name was not defined by
DEFER, or if the name has not been set to execute an xt.
Compilation: ( “hspacesiname” – – )
Skip leading spaces and parse name delimited by a space. Append the run-time semantics
given below to the current definition. An ambiguous condition exists if name was not
defined by DEFER.
Run-time: ( – – xt )
xt is the execution token that name is set to execute. An ambiguous condition exists if
name has not been set to execute an xt.
An ambiguous condition exists if POSTPONE, [COMPILE], [’] or ’ is applied to
ACTION-OF.
See: 6.2.1173 DEFER, 6.2.1175 DEFER!, 6.2.1177 DEFER@, 6.2.1725 IS.
( u “hspacesiname” – – )
Skip leading space delimiters. Parse name delimited by a space. Create a definition for
name, with the execution semantics defined below. Reserve u address units at an aligned
address. Contiguity of this region with any other region is undefined.
name Execution: ( – – a-addr )
a-addr is the address of the space reserved by BUFFER: when it defined name. The
program is responsible for initializing the contents.
See: A.6.2.0825 BUFFER:.
( “hspacesiname” – – )
Skip leading space delimiters. Parse name delimited by a space. Create a definition for
name with the execution semantics defined below.
name Execution: ( i * x – – j * x )
Execute the xt that name is set to execute. An ambiguous condition exists if name has
not been set to execute an xt.
See: 6.2.0698 ACTION-OF, 6.2.1175 DEFER!, 6.2.1177 DEFER@, 6.2.1725 IS.
( xt2 xt1 – – )
Set the word xt1 to execute xt2. An ambiguous condition exists if xt1 is not for a word
defined by DEFER.
See: 6.2.0698 ACTION-OF, 6.2.1173 DEFER, 6.2.1177 DEFER@, 6.2.1725 IS.
( xt1 – – xt2 )
xt2 is the execution token xt1 is set to execute. An ambiguous condition exists if xt1 is not
the execution token of a word defined by DEFER, or if xt1 has not been set to execute an
xt.
See: 6.2.0698 ACTION-OF, 6.2.1173 DEFER, 6.2.1175 DEFER!, 6.2.1725 IS.
( addr u – – )
If u is greater than zero, clear all bits in each of u consecutive address units of memory
beginning at addr.
( – – false )
Return a false flag.
See: 3.1.3.1 Flags
( –– )
Set contents of BASE to sixteen.
( c-addr u – – )
Adds the string represented by c-addr u to the pictured numeric output string. An am-
biguous condition exists if HOLDS executes outside of a <# #> delimited number con-
version.
See: 6.1.1670 HOLD.
Interpretation: ( xt “hspacesiname” – – )
Skip leading spaces and parse name delimited by a space. Set name to execute xt.
An ambiguous condition exists if name was not defined by DEFER.
Compilation: ( “hspacesiname” – – )
Skip leading spaces and parse name delimited by a space. Append the run-time semantics
given below to the current definition. An ambiguous condition exists if name was not
defined by DEFER.
Run-time: ( xt – – )
Set name to execute xt.
An ambiguous condition exists if POSTPONE, [COMPILE], [’] or ’ is applied to IS.
See: 6.2.0698 ACTION-OF, 6.2.1173 DEFER, 6.2.1175 DEFER!, 6.2.1177 DEFER@.
( “hspacesiname” – – )
Skip leading space delimiters. Parse name delimited by a space. Create a definition for
name with the execution semantics defined below.
name Execution: ( – – )
Restore all dictionary allocation and search order pointers to the state they had just prior
to the definition of name. Remove the definition of name and all subsequent definitions.
Restoration of any structures still existing that could refer to deleted definitions or deal-
located data space is not necessarily provided. No other contextual information such as
numeric base is affected.
See: 3.4.1 Parsing, 15.6.2.1580 FORGET, A.6.2.1850 MARKER.
( x1 x2 – – x2 )
Drop the first item below the top of stack.
( – – c-addr )
c-addr is the address of a transient region that can be used to hold data for intermediate
processing.
See: 3.3.3.6 Other transient regions, A.6.2.2000 PAD.
( “hspacesinamehspacei” – – c-addr u )
Skip leading space delimiters. Parse name delimited by a space.
c-addr is the address of the selected string within the input buffer and u is its length in
characters. If the parse area is empty or contains only white space, the resulting string
has length zero.
( xu. . . x1 x0 u – – xu. . . x1 x0 xu )
Remove u. Copy the xu to the top of the stack. An ambiguous condition exists if there
are less than u+2 items on the stack before PICK is executed.
See: A.6.2.2030 PICK.
( – – flag )
Attempt to fill the input buffer from the input source, returning a true flag if successful.
When the input source is the user input device, attempt to receive input into the terminal
input buffer. If successful, make the result the input buffer, set >IN to zero, and return
true. Receipt of a line containing no characters is considered successful. If there is no
input available from the current input source, return false.
When the input source is a string from EVALUATE, return false and perform no other
action.
See: 7.6.2.2125 REFILL, 11.6.2.2125 REFILL, A.6.2.2125 REFILL.
( xn . . . x1 n – – flag )
Attempt to restore the input source specification to the state described by x1 through xn.
flag is true if the input source specification cannot be so restored.
An ambiguous condition exists if the input source represented by the arguments is not
the same as the current input source.
See: 15.6.2.1908 N>R, 15.6.2.1940 NR>, A.6.2.2182 SAVE-INPUT.
( xu xu-1 . . . x0 u – – xu-1 . . . x0 xu )
Remove u. Rotate u+1 items on the top of the stack. An ambiguous condition exists if
there are less than u+2 items on the stack before ROLL is executed.
See: A.6.2.2150 ROLL.
An ambiguous condition exists if a \ is placed before any character, other than those
defined in here.
Run-time: ( – – c-addr u )
Return c-addr and u describing a string consisting of the translation of the characters
ccc. A program shall not alter the returned string.
See: 3.4.1 Parsing, 6.2.0855 C", 11.6.1.2165 S", A.6.1.2165 S".
( – – xn . . . x1 n )
x1 through xn describe the current state of the input source specification for later use by
RESTORE-INPUT.
See: 15.6.2.1908 N>R, 15.6.2.1940 NR>, A.6.2.2182 SAVE-INPUT.
( – – 0 | -1 )
Identifies the input source as follows:
SOURCE-ID Input source
-1 String (via EVALUATE)
0 User input device
See: 11.6.1.2218 SOURCE-ID.
Interpretation: ( i * x “hspacesiname” – – )
Skip leading spaces and parse name delimited by a space. Perform the “TO name run-
time” semantics given in the definition for the defining word of name. An ambiguous
condition exists if name was not defined by a word with “TO name run-time” semantics.
Compilation: ( “hspacesiname” – – )
Skip leading spaces and parse name delimited by a space. Append the “TO name run-
time” semantics given in the definition for the defining word of name to the current
definition. An ambiguous condition exists if name was not defined by a word with “TO
name run-time” semantics.
Note: An ambiguous condition exists if any of POSTPONE, [COMPILE], ’ or [’] are applied
to TO.
See: 6.2.2405 VALUE, 8.6.2.0435 2VALUE, 12.6.2.1628 FVALUE, 13.6.1.0086 (LOCAL),
A.6.2.2295 TO.
( – – true )
Return a true flag, a single-cell value with all bits set.
See: 3.1.3.1 Flags, A.6.2.2298 TRUE.
( x1 x2 – – x2 x1 x2 )
Copy the first (top) stack item below the second stack item.
( u n –– )
Display u right aligned in a field n characters wide. If the number of characters required
to display u is greater than n, all digits are displayed with no leading spaces in a field as
wide as necessary.
( u1 u2 – – flag )
flag is true if and only if u1 is greater than u2.
See: 6.1.0540 >.
( –– u )
u is the amount of space remaining in the region addressed by HERE, in address units.
( x “hspacesiname” – – )
Skip leading space delimiters. Parse name delimited by a space. Create a definition for
name with the execution semantics defined below, with an initial value equal to x.
name is referred to as a “value”.
name Execution: ( – – x )
Place x on the stack. The value of x is that given when name was created, until the phrase
x TO name is executed, causing a new value of x to be assigned to name.
TO name Run-time: ( x – – )
Assign the value x to name.
See: 3.4.1 Parsing, 6.2.2295 TO, A.6.2.2405 VALUE.
( n1 | u1 n2 | u2 n3 | u3 – – flag )
Perform a comparison of a test value n1 | u1 with a lower limit n2 | u2 and an upper limit
n3 | u3, returning true if either (n2 | u2 < n3 | u3 and (n2 | u2 <= n1 | u1 and n1 | u1 < n3 | u3))
or (n2 | u2 > n3 | u3 and (n2 | u2 <= n1 | u1 or n1 | u1 < n3 | u3)) is true, returning false
otherwise. An ambiguous condition exists n1 | u1, n2 | u2, and n3 | u3 are not all the same
type.
See: A.6.2.2440 WITHIN.
7.1 Introduction
7.2 Additional terms
block: 1024 characters of data on mass storage, designated by a block number.
block buffer: A block-sized region of data space where a block is made temporarily available for use. The
current block buffer is the block buffer most recently accessed by BLOCK, BUFFER, LOAD, LIST,
or THRU.
7.3.3 Parsing
The Block word set implements an alternative input source for the text interpreter. When the input source
is a block, BLK shall contain the non-zero block number and the input buffer is the 1024-character buffer
containing that block.
The phrase “Providing name(s) from the Block Extensions word set” shall be appended to the label of any
Standard System that provides portions of the Block Extensions word set.
The phrase “Providing the Block Extensions word set” shall be appended to the label of any Standard
System that provides all of the Block and Block Extensions word sets.
7.6 Glossary
7.6.1 Block words
7.6.1.0790 BLK “b-l-k” BLOCK
( – – a-addr )
a-addr is the address of a cell containing zero or the number of the mass-storage block
being interpreted. If BLK contains zero, the input source is not a block and can be
identified by SOURCE-ID, if SOURCE-ID is available. An ambiguous condition exists
if a program directly alters the contents of BLK.
See: 7.3.2 Block buffer regions.
( u – – a-addr )
a-addr is the address of the first character of the block buffer assigned to mass-storage
block u. An ambiguous condition exists if u is not an available block number.
If block u is already in a block buffer, a-addr is the address of that block buffer.
If block u is not already in memory and there is an unassigned block buffer, transfer
block u from mass storage to an unassigned block buffer. a-addr is the address of that
block buffer.
If block u is not already in memory and there are no unassigned block buffers, unassign
a block buffer. If the block in that buffer has been UPDATEd, transfer the block to mass
storage and transfer block u from mass storage into that buffer. a-addr is the address of
that block buffer.
At the conclusion of the operation, the block buffer pointed to by a-addr is the current
block buffer and is assigned to u.
( u – – a-addr )
a-addr is the address of the first character of the block buffer assigned to block u. The
contents of the block are unspecified. An ambiguous condition exists if u is not an
available block number.
If block u is already in a block buffer, a-addr is the address of that block buffer.
If block u is not already in memory and there is an unassigned buffer, a-addr is the
address of that block buffer.
If block u is not already in memory and there are no unassigned block buffers, unassign
a block buffer. If the block in that buffer has been UPDATEd, transfer the block to mass
storage. a-addr is the address of that block buffer.
At the conclusion of the operation, the block buffer pointed to by a-addr is the current
block buffer and is assigned to u.
See: 7.6.1.0800 BLOCK.
( –– )
Perform the function of SAVE-BUFFERS, then unassign all block buffers.
( i*x u –– j*x )
Save the current input-source specification. Store u in BLK (thus making block u the
input source and setting the input buffer to encompass its contents), set >IN to zero, and
interpret. When the parse area is exhausted, restore the prior input source specification.
Other stack effects are due to the words LOADed.
An ambiguous condition exists if u is zero or is not a valid block number.
See: 3.4 The Forth text interpreter.
( –– )
Transfer the contents of each UPDATEd block buffer to mass storage. Mark all buffers
as unmodified.
( –– )
Mark the current block buffer as modified. An ambiguous condition exists if there is no
current block buffer.
UPDATE does not immediately cause I/O.
See: 7.6.1.0800 BLOCK, 7.6.1.0820 BUFFER, 7.6.1.1559 FLUSH,
7.6.1.2180 SAVE-BUFFERS.
( –– )
Unassign all block buffers. Do not transfer the contents of any UPDATEd block buffer to
mass storage.
See: 7.6.1.0800 BLOCK.
( u –– )
Display block u in an implementation-defined format. Store u in SCR.
See: 7.6.1.0800 BLOCK.
( – – flag )
Extend the execution semantics of 6.2.2125 REFILL with the following:
When the input source is a block, make the next block the input source and current input
buffer by adding one to the value of BLK and setting >IN to zero. Return true if the new
value of BLK is a valid block number, otherwise false.
See: 6.2.2125 REFILL, 11.6.2.2125 REFILL.
( – – a-addr )
a-addr is the address of a cell containing the block number of the block most recently
LISTed.
See: A.7.6.2.2190 SCR.
( i * x u1 u2 – – j * x )
LOAD the mass storage blocks numbered u1 through u2 in sequence. Other stack effects
are due to the words LOADed.
8.1 Introduction
Sixteen-bit Forth systems often use double-length numbers. However, many Forths on small embedded
systems do not, and many users of Forth on systems with a cell size of 32 bits or more find that the use of
double-length numbers is much diminished. Therefore, the words that manipulate double-length entities
have been placed in this optional word set.
– no additional requirements.
8.4.1.2 Ambiguous conditions
– no additional requirements.
The phrase “Providing name(s) from the Double-Number Extensions word set” shall be appended to the
label of any Standard System that provides portions of the Double-Number Extensions word set.
The phrase “Providing the Double-Number Extensions word set” shall be appended to the label of any
Standard System that provides all of the Double-Number and Double-Number Extensions word sets.
8.6 Glossary
8.6.1 Double-Number words
8.6.1.0360 2CONSTANT “two-constant” DOUBLE
( x1 x2 “hspacesiname” – – )
Skip leading space delimiters. Parse name delimited by a space. Create a definition for
name with the execution semantics defined below.
name is referred to as a “two-constant”.
name Execution: ( – – x1 x2 )
Place cell pair x1 x2 on the stack.
See: 3.4.1 Parsing, A.8.6.1.0360 2CONSTANT.
( “hspacesiname” – – )
Skip leading space delimiters. Parse name delimited by a space. Create a definition for
name with the execution semantics defined below. Reserve two consecutive cells of data
space.
name is referred to as a “two-variable”.
name Execution: ( – – a-addr )
a-addr is the address of the first (lowest address) cell of two consecutive cells in data
space reserved by 2VARIABLE when it defined name. A program is responsible for
initializing the contents.
See: 3.4.1 Parsing, 6.1.2410 VARIABLE, A.8.6.1.0440 2VARIABLE.
( d –– )
Display d in free field format.
( d n –– )
Display d right aligned in a field n characters wide. If the number of characters required
to display d is greater than n, all digits are displayed with no leading spaces in a field as
wide as necessary.
See: A.8.6.1.1070 D.R.
( d – – flag )
flag is true if and only if d is less than zero.
( xd – – flag )
flag is true if and only if xd is equal to zero.
( xd1 – – xd2 )
xd2 is the result of shifting xd1 one bit toward the most-significant bit, filling the vacated
least-significant bit with zero.
( xd1 – – xd2 )
xd2 is the result of shifting xd1 one bit toward the least-significant bit, leaving the most-
significant bit unchanged.
( d1 d2 – – flag )
flag is true if and only if d1 is less than d2.
( d –– n )
n is the equivalent of d. An ambiguous condition exists if d lies outside the range of a
signed single-cell number.
See: A.8.6.1.1140 D>S.
( d – – ud )
ud is the absolute value of d.
( d1 d2 – – d3 )
d3 is the greater of d1 and d2.
( d1 d2 – – d3 )
d3 is the lesser of d1 and d2.
( d1 – – d2 )
d2 is the negation of d1.
( d1 n1 +n2 – – d2 )
Multiply d1 by n1 producing the triple-cell intermediate result t. Divide t by +n2 giving
the double-cell quotient d2. An ambiguous condition exists if +n2 is zero or negative, or
the quotient lies outside of the range of a double-precision signed integer.
See: A.8.6.1.1820 M*/.
( d1 | ud1 n – – d2 | ud2 )
Add n to d1 | ud1, giving the sum d2 | ud2.
See: A.8.6.1.1830 M+.
( x1 x2 x3 x4 x5 x6 – – x3 x4 x5 x6 x1 x2 )
Rotate the top three cell pairs on the stack bringing cell pair x1 x2 to the top of the stack.
( x1 x2 “hspacesiname” – – )
Skip leading space delimiters. Parse name delimited by a space. Create a definition for
name with the execution semantics defined below, with an initial value of x1 x2.
name is referred to as a “two-value”.
name Execution: ( – – x1 x2 )
Place cell pair x1 x2 on the stack. The value of x1 x2 is that given when name was created,
until the phrase “x1 x2 TO name” is executed, causing a new cell pair x1 x2 to be assigned
to name.
TO name Run-time: ( x1 x2 – – )
Assign the cell pair x1 x2 to name.
See: 3.4.1 Parsing and 6.2.2295 TO, A.8.6.2.0435 2VALUE.
9.1 Introduction
9.2 Additional terms and notation
None.
– Values used in the system by 9.6.1.0875 CATCH and 9.6.1.2275 THROW (9.3.1 THROW values,
9.3.4 Possible actions on an ambiguous condition).
9.4.1.2 Ambiguous conditions
– no additional requirements.
9.4.1.3 Other system documentation
– no additional requirements.
9.6 Glossary
9.6.1 Exception words
9.6.1.0875 CATCH EXCEPTION
( i * x xt – – j * x 0 | i * x n )
Push an exception frame on the exception stack and then execute the execution token xt
(as with EXECUTE) in such a way that control can be transferred to a point just after
CATCH if THROW is executed during the execution of xt.
If the execution of xt completes normally (i.e., the exception frame pushed by this CATCH
is not popped by an execution of THROW) pop the exception frame and return zero on top
of the data stack, above whatever stack items would have been returned by xt EXECUTE.
Otherwise, the remainder of the execution semantics are given by THROW.
See: A.9.6.1.2275 THROW.
10.1 Introduction
10.2 Additional terms and notation
None.
Programs that use more than seven bits of a character by EKEY have an environmental dependency.
See: 3.1.2 Character types.
– no additional requirements.
– no additional requirements.
10.6 Glossary
10.6.1 Facility words
10.6.1.0742 AT-XY “at-x-y” FACILITY
( u1 u2 – – )
Perform implementation-dependent steps so that the next character displayed will appear
in column u1, row u2 of the user output device, the upper left corner of which is column
zero, row zero. An ambiguous condition exists if the operation cannot be performed on
the user output device with the specified parameters.
( – – flag )
If a character is available, return true. Otherwise, return false. If non-character keyboard
events are available before the first valid character, they are discarded and are subse-
quently unavailable. The character shall be returned by the next execution of KEY.
After KEY? returns with a value of true, subsequent executions of KEY? prior to the
execution of KEY or EKEY also return true, without discarding keyboard events.
See: A.10.6.1.1755 KEY?.
( –– )
Move to another page for output. Actual function depends on the output device. On a
terminal, PAGE clears the screen and resets the cursor position to the upper left corner.
On a printer, PAGE performs a form feed.
( n1 n2 “hspacesiname” – – n3 )
Skip leading space delimiters. Parse name delimited by a space. Create a definition for
name with the execution semantics defined below. Return n3 = n1 + n2 where n1 is the
offset in the data structure before +FIELD executes, and n2 is the size of the data to be
added to the data structure. n1 and n2 are in address units.
name Execution: ( addr1 – – addr2 )
Add n1 to addr1 giving addr2.
See: 10.6.2.0763 BEGIN-STRUCTURE, 10.6.2.1336 END-STRUCTURE,
10.6.2.0893 CFIELD:, 10.6.2.1518 FIELD:, 12.6.2.1517 FFIELD:,
12.6.2.2206.40 SFFIELD:, 12.6.2.1207.40 DFFIELD:, A.10.6.2.0135 +FIELD.
( “hspacesiname” – – struct-sys 0 )
Skip leading space delimiters. Parse name delimited by a space. Create a definition for
name with the execution semantics defined below. Return a struct-sys (zero or more
implementation dependent items) that will be used by END-STRUCTURE and an initial
offset of 0.
name Execution: ( – – +n )
+n is the size in memory expressed in address units of the data structure. An ambiguous
condition exists if name is executed prior to the associated END-STRUCTURE being
executed.
See: 10.6.2.0135 +FIELD, 10.6.2.1336 END-STRUCTURE,
A.10.6.2.0763 BEGIN-STRUCTURE.
( n1 “hspacesiname” – – n2 )
Skip leading space delimiters. Parse name delimited by a space. Offset is the first char-
acter aligned value greater than or equal to n1. n2 = offset + 1 character.
Create a definition for name with the execution semantics given below.
name Execution: ( addr1 – – addr2 )
Add the offset calculated during the compile-time action to addr1 giving the address
addr2.
See: 10.6.2.0135 +FIELD, 10.6.2.0763 BEGIN-STRUCTURE,
10.6.2.1336 END-STRUCTURE, A.10.6.2.1518 FIELD:.
( –– x )
Receive one keyboard event x. The encoding of keyboard events is implementation de-
fined.
See: 6.1.1750 KEY, 10.6.1.1755 KEY?, A.10.6.2.1305 EKEY.
( x – – u flag )
If the keyboard event x corresponds to a keypress in the implementation-defined special
key set, return that key’s id u and true. Otherwise return x and false.
Note: The keyboard may lack some of the keys, or the capability to report them. Programs
should be written such that they also work (although less conveniently or with less func-
tionality) if these key numbers cannot be produced.
See: 10.6.2.1305 EKEY, 10.6.2.1740.01 K-ALT-MASK, 10.6.2.1740.02 K-CTRL-MASK,
10.6.2.1740.03 K-DELETE, 10.6.2.1740.04 K-DOWN, 10.6.2.1740.05 K-END,
10.6.2.1740.06 K-F1, 10.6.2.1740.07 K-F10, 10.6.2.1740.08 K-F11,
10.6.2.1740.09 K-F12, 10.6.2.1740.10 K-F2, 10.6.2.1740.11 K-F3,
10.6.2.1740.12 K-F4, 10.6.2.1740.13 K-F5, 10.6.2.1740.14 K-F6,
10.6.2.1740.15 K-F7, 10.6.2.1740.16 K-F8, 10.6.2.1740.17 K-F9,
10.6.2.1740.18 K-HOME, 10.6.2.1740.19 K-INSERT, 10.6.2.1740.20 K-LEFT,
10.6.2.1740.21 K-NEXT, 10.6.2.1740.22 K-PRIOR, 10.6.2.1740.23 K-RIGHT,
10.6.2.1740.24 K-SHIFT-MASK, 10.6.2.1740.25 K-UP,
A.10.6.2.1306.40 EKEY>FKEY.
( – – flag )
If a keyboard event is available, return true. Otherwise return false. The event shall be
returned by the next execution of EKEY.
After EKEY? returns with a value of true, subsequent executions of EKEY? prior to the
execution of KEY, KEY? or EKEY also return true, referring to the same event.
( – – flag )
flag is true if the user output device is ready to accept data and the execution of EMIT
in place of EMIT? would not have suffered an indefinite delay. If the device status is
indeterminate, flag is true.
See: A.10.6.2.1325 EMIT?.
( struct-sys +n – – )
Terminate definition of a structure started by BEGIN-STRUCTURE.
See: 10.6.2.0135 +FIELD, 10.6.2.0763 BEGIN-STRUCTURE.
( n1 “hspacesiname” – – n2 )
Skip leading space delimiters. Parse name delimited by a space. Offset is the first cell
aligned value greater than or equal to n1. n2 = offset + 1 cell.
Create a definition for name with the execution semantics given below.
name Execution: ( addr1 – – addr2 )
Add the offset calculated during the compile-time action to addr1 giving the address
addr2.
See: 10.6.2.0135 +FIELD, 10.6.2.0763 BEGIN-STRUCTURE,
10.6.2.1336 END-STRUCTURE, A.10.6.2.1518 FIELD:.
( –– u )
Mask for the A LT key, that can be ORed with the key value to produce a value that the
sequence EKEY EKEY>FKEY may produce when the user presses the corresponding key
combination.
See: 10.6.2.1306.40 EKEY>FKEY, A.10.6.2.1306.40 EKEY>FKEY.
( –– u )
Mask for the C TRL key, that can be ORed with the key value to produce a value that the
sequence EKEY EKEY>FKEY may produce when the user presses the corresponding key
combination.
See: 10.6.2.1306.40 EKEY>FKEY, A.10.6.2.1306.40 EKEY>FKEY.
( –– u )
Leaves the value u that the sequence EKEY EKEY>FKEY would produce when the user
presses the “Delete” key.
See: 10.6.2.1306.40 EKEY>FKEY, A.10.6.2.1306.40 EKEY>FKEY.
( –– u )
Leaves the value u that the sequence EKEY EKEY>FKEY would produce when the user
presses the “cursor down” key.
See: 10.6.2.1306.40 EKEY>FKEY, A.10.6.2.1306.40 EKEY>FKEY.
( –– u )
Leaves the value u that the sequence EKEY EKEY>FKEY would produce when the user
presses the “End” key.
See: 10.6.2.1306.40 EKEY>FKEY, A.10.6.2.1306.40 EKEY>FKEY.
( –– u )
Leaves the value u that the sequence EKEY EKEY>FKEY would produce when the user
presses the “F1” key.
See: 10.6.2.1306.40 EKEY>FKEY, A.10.6.2.1306.40 EKEY>FKEY.
( –– u )
Leaves the value u that the sequence EKEY EKEY>FKEY would produce when the user
presses the “F10” key.
See: 10.6.2.1306.40 EKEY>FKEY, A.10.6.2.1306.40 EKEY>FKEY.
( –– u )
Leaves the value u that the sequence EKEY EKEY>FKEY would produce when the user
presses the “F11” key.
See: 10.6.2.1306.40 EKEY>FKEY, A.10.6.2.1306.40 EKEY>FKEY.
( –– u )
Leaves the value u that the sequence EKEY EKEY>FKEY would produce when the user
presses the “F12” key.
See: 10.6.2.1306.40 EKEY>FKEY, A.10.6.2.1306.40 EKEY>FKEY.
( –– u )
Leaves the value u that the sequence EKEY EKEY>FKEY would produce when the user
presses the “F2” key.
See: 10.6.2.1306.40 EKEY>FKEY, A.10.6.2.1306.40 EKEY>FKEY.
( –– u )
Leaves the value u that the sequence EKEY EKEY>FKEY would produce when the user
presses the “F3” key.
See: 10.6.2.1306.40 EKEY>FKEY, A.10.6.2.1306.40 EKEY>FKEY.
( –– u )
Leaves the value u that the sequence EKEY EKEY>FKEY would produce when the user
presses the “F4” key.
See: 10.6.2.1306.40 EKEY>FKEY, A.10.6.2.1306.40 EKEY>FKEY.
( –– u )
Leaves the value u that the sequence EKEY EKEY>FKEY would produce when the user
presses the “F5” key.
See: 10.6.2.1306.40 EKEY>FKEY, A.10.6.2.1306.40 EKEY>FKEY.
( –– u )
Leaves the value u that the sequence EKEY EKEY>FKEY would produce when the user
presses the “F6” key.
See: 10.6.2.1306.40 EKEY>FKEY, A.10.6.2.1306.40 EKEY>FKEY.
( –– u )
Leaves the value u that the sequence EKEY EKEY>FKEY would produce when the user
presses the “F7” key.
See: 10.6.2.1306.40 EKEY>FKEY, A.10.6.2.1306.40 EKEY>FKEY.
( –– u )
Leaves the value u that the sequence EKEY EKEY>FKEY would produce when the user
presses the “F8” key.
See: 10.6.2.1306.40 EKEY>FKEY, A.10.6.2.1306.40 EKEY>FKEY.
( –– u )
Leaves the value u that the sequence EKEY EKEY>FKEY would produce when the user
presses the “F9” key.
See: 10.6.2.1306.40 EKEY>FKEY, A.10.6.2.1306.40 EKEY>FKEY.
( –– u )
Leaves the value u that the sequence EKEY EKEY>FKEY would produce when the user
presses the “home” or “Pos1” key.
See: 10.6.2.1306.40 EKEY>FKEY, A.10.6.2.1306.40 EKEY>FKEY.
( –– u )
Leaves the value u that the sequence EKEY EKEY>FKEY would produce when the user
presses the “Insert” key.
See: 10.6.2.1306.40 EKEY>FKEY, A.10.6.2.1306.40 EKEY>FKEY.
( –– u )
Leaves the value u that the sequence EKEY EKEY>FKEY would produce when the user
presses the “cursor left” key.
See: 10.6.2.1306.40 EKEY>FKEY, A.10.6.2.1306.40 EKEY>FKEY.
( –– u )
Leaves the value u that the sequence EKEY EKEY>FKEY would produce when the user
presses the “PgDn” (Page Down) or “Next” key.
See: 10.6.2.1306.40 EKEY>FKEY, A.10.6.2.1306.40 EKEY>FKEY.
( –– u )
Leaves the value u that the sequence EKEY EKEY>FKEY would produce when the user
presses the “PgUp” (Page Up) or “Prior” key.
See: 10.6.2.1306.40 EKEY>FKEY, A.10.6.2.1306.40 EKEY>FKEY.
( –– u )
Leaves the value u that the sequence EKEY EKEY>FKEY would produce when the user
presses the “cursor right” key.
See: 10.6.2.1306.40 EKEY>FKEY, A.10.6.2.1306.40 EKEY>FKEY.
( –– u )
Mask for the S HIFT key, that can be ORed with the key value to produce a value that the
sequence EKEY EKEY>FKEY may produce when the user presses the corresponding key
combination.
See: 10.6.2.1306.40 EKEY>FKEY, A.10.6.2.1306.40 EKEY>FKEY.
( –– u )
Leaves the value u that the sequence EKEY EKEY>FKEY would produce when the user
presses the “cursor up” key.
See: 10.6.2.1306.40 EKEY>FKEY, A.10.6.2.1306.40 EKEY>FKEY.
( u –– )
Wait at least u milliseconds.
Note: The actual length and variability of the time period depends upon the implementation-de-
fined resolution of the system clock and upon other system and computer characteristics
beyond the scope of this standard.
See: A.10.6.2.1905 MS.
11.1 Introduction
These words provide access to mass storage in the form of “files” under the following assumptions:
– files are provided by a host operating system;
– file names are represented as character strings;
– the format of file names is determined by the host operating system;
– an open file is identified by a single-cell file identifier (fileid);
– file-state information (e.g., position, size) is managed by the host operating system;
– file contents are accessed as a sequence of characters;
– file read operations return an actual transfer count, which can differ from the requested transfer count.
File identifiers are implementation-dependent single-cell values that are passed to file operators to designate
specific files. Opening a file assigns a file identifier, which remains valid until closed.
11.3.1.3 File access methods (11.3.1.3)
A character string containing the name of the file. The file name may include an implementation-dependent
path name. The format of file names is implementation defined.
11.3.5 Parsing
When parsing from a text file using a space delimiter, control characters shall be treated the same as the
space character.
Lines of at least 128 characters shall be supported. A program that requires lines of more than 128 charac-
ters has an environmental dependency.
A program may reposition the parse area within the input buffer by manipulating the contents of >IN.
More extensive repositioning can be accomplished using SAVE-INPUT and RESTORE-INPUT.
See: 3.4.1 Parsing.
– no additional requirements.
– no additional requirements.
11.6 Glossary
11.6.1 File Access words
11.6.1.0080 ( “paren” FILE
( “ccchpareni” – – )
Extend the semantics of 6.1.0080 ( to include:
When parsing from a text file, if the end of the parse area is reached before a right
parenthesis is found, refill the input buffer from the next line of the file, set >IN to zero,
and resume parsing, repeating this process until either a right parenthesis is found or the
end of the file is reached.
( fam1 – – fam2 )
Modify the implementation-defined file access method fam1 to additionally select a
“binary”, i.e., not line oriented, file access method, giving access method fam2.
See: 11.6.1.2054 R/O, 11.6.1.2056 R/W, 11.6.1.2425 W/O, A.11.6.1.0765 BIN.
( fileid – – ior )
Close the file identified by fileid. ior is the implementation-defined I/O result code.
( c-addr u – – ior )
Delete the file named in the character string specified by c-addr u. ior is the implement-
ation-defined I/O result code.
( fileid – – ud ior )
ud is the current file position for the file identified by fileid. ior is the implementation-
defined I/O result code. ud is undefined if ior is non-zero.
( fileid – – ud ior )
ud is the size, in characters, of the file identified by fileid. ior is the implementation-
defined I/O result code. This operation does not affect the value returned by FILE-
POSITION. ud is undefined if ior is non-zero.
( i * x fileid – – j * x )
Remove fileid from the stack. Save the current input source specification, including
the current value of SOURCE-ID. Store fileid in SOURCE-ID. Make the file specified
by fileid the input source. Store zero in BLK. Other stack effects are due to the words
included.
Repeat until end of file: read a line from the file, fill the input buffer from the contents
of that line, set >IN to zero, and interpret.
Text interpretation begins at the file position where the next file read would occur.
When the end of the file is reached, close the file and restore the input source specification
to its saved value.
An ambiguous condition exists if fileid is invalid, if there is an I/O exception reading
fileid, or if an I/O exception occurs while closing fileid. When an ambiguous condition
exists, the status (open or closed) of any files that were being interpreted is implement-
ation-defined.
See: 11.3.3 Input source, A.11.6.1.1717 INCLUDE-FILE.
( i * x c-addr u – – j * x )
Remove c-addr u from the stack. Save the current input source specification, including
the current value of SOURCE-ID. Open the file specified by c-addr u, store the resulting
fileid in SOURCE-ID, and make it the input source. Store zero in BLK. Other stack
effects are due to the words included.
Repeat until end of file: read a line from the file, fill the input buffer from the contents
of that line, set >IN to zero, and interpret.
Text interpretation begins at the start of the file.
When the end of the file is reached, close the file and restore the input source specification
to its saved value.
An ambiguous condition exists if the named file can not be opened, if an I/O excep-
tion occurs reading the file, or if an I/O exception occurs while closing the file. When
an ambiguous condition exists, the status (open or closed) of any files that were being
interpreted is implementation-defined.
INCLUDED may allocate memory in data space before it starts interpreting the file.
See: 11.6.1.1717 INCLUDE-FILE, A.11.6.1.1718 INCLUDED.
( – – fam )
fam is the implementation-defined value for selecting the “read only” file access method.
See: 11.6.1.1010 CREATE-FILE, 11.6.1.1970 OPEN-FILE.
( – – fam )
fam is the implementation-defined value for selecting the “read/write” file access method.
See: 11.6.1.1010 CREATE-FILE, 11.6.1.1970 OPEN-FILE.
At the conclusion of the operation, FILE-POSITION returns the next file position after
the last character read.
See: A.11.6.1.2080 READ-FILE.
( ud fileid – – ior )
Reposition the file identified by fileid to ud. ior is the implementation-defined I/O result
code. An ambiguous condition exists if the file is positioned outside the file boundaries.
At the conclusion of the operation, FILE-POSITION returns the value ud.
( ud fileid – – ior )
Set the size of the file identified by fileid to ud. ior is the implementation-defined I/O
result code.
If the resultant file is larger than the file before the operation, the portion of the file added
as a result of the operation might not have been written.
At the conclusion of the operation, FILE-SIZE returns the value ud and FILE-
POSITION returns an unspecified value.
See: 11.6.1.2080 READ-FILE, 11.6.1.2090 READ-LINE.
( – – 0 | -1 | fileid )
Extend 6.2.2218 SOURCE-ID to include text-file input as follows:
SOURCE-ID Input source
fileid Text file “fileid”
-1 String (via EVALUATE)
0 User input device
An ambiguous condition exists if SOURCE-ID is used when BLK contains a non-zero
value.
( – – fam )
fam is the implementation-defined value for selecting the “write only” file access method.
See: 11.6.1.1010 CREATE-FILE, 11.6.1.1970 OPEN-FILE.
( c-addr u – – x ior )
Return the status of the file identified by the character string c-addr u. If the file ex-
ists, ior is zero; otherwise ior is the implementation-defined I/O result code. x contains
implementation-defined information about the file.
( fileid – – ior )
Attempt to force any buffered information written to the file referred to by fileid to be
written to mass storage, and the size information for the file to be recorded in the storage
directory if changed. If the operation is successful, ior is zero. Otherwise, it is an
implementation-defined I/O result code.
( i * x “name” – – j * x )
Skip leading white space and parse name delimited by a white space character. Push the
address and length of the name on the stack and perform the function of INCLUDED.
See: 11.6.1.1718 INCLUDED, A.11.6.2.1714 INCLUDE.
( – – flag )
Extend the execution semantics of 6.2.2125 REFILL with the following:
When the input source is a text file, attempt to read the next line from the text-input file.
If successful, make the result the current input buffer, set >IN to zero, and return true.
Otherwise return false.
See: 6.2.2125 REFILL, 7.6.2.2125 REFILL.
( i * x “name” – – i * x )
Skip leading white space and parse name delimited by a white space character. Push the
address and length of the name on the stack and perform the function of REQUIRED.
See: 11.6.2.2144.50 REQUIRED, A.11.6.2.2144.10 REQUIRE.
( i * x c-addr u – – i * x )
If the file specified by c-addr u has been INCLUDED or REQUIRED already, but not
between the definition and execution of a marker (or equivalent usage of FORGET),
discard c-addr u; otherwise, perform the function of INCLUDED.
An ambiguous condition exists if a file is REQUIRED while it is being REQUIRED or
INCLUDED.
An ambiguous condition exists, if a marker is defined outside and executed inside a file
or vice versa, and the file is REQUIRED again.
An ambiguous condition exists if the same file is REQUIRED twice using different names
(e.g., through symbolic links), or different files with the same name are REQUIRED (by
doing some renaming between the invocations of REQUIRED).
An ambiguous condition exists if the stack effect of including the file is not ( i * x – –
i*x ) .
See: A.11.6.2.2144.50 REQUIRED.
12.1 Introduction
12.2 Additional terms and notation
12.2.1 Definition of terms
float-aligned address: The address of a memory location at which a floating-point number can be ac-
cessed.
double-float-aligned address: The address of a memory location at which a 64-bit IEEE double-precision
floating-point number can be accessed.
single-float-aligned address: The address of a memory location at which a 32-bit IEEE single-precision
floating-point number can be accessed.
IEEE floating-point number: A single- or double-precision floating-point number as defined in
ANSI/IEEE 754-1985.
12.2.2 Notation
12.2.2.2 Stack notation
12.3.1.1 Addresses
The set of float-aligned addresses is an implementation-defined subset of the set of aligned addresses.
Adding the size of a floating-point number to a float-aligned address shall produce a float-aligned address.
The set of double-float-aligned addresses is an implementation-defined subset of the set of aligned ad-
dresses. Adding the size of a 64-bit IEEE double-precision floating-point number to a double-float-aligned
address shall produce a double-float-aligned address.
The set of single-float-aligned addresses is an implementation-defined subset of the set of aligned addresses.
Adding the size of a 32-bit IEEE single-precision floating-point number to a single-float-aligned address
shall produce a single-float-aligned address.
12.3.1.2 Floating-point numbers
The internal representation of a floating-point number, including the format and precision of the significand
and the format and range of the exponent, is implementation defined.
Any rounding or truncation of floating-point numbers is implementation defined.
12.3.6 Variables
A program may address memory in data space regions made available by FVARIABLE. These regions may
be non-contiguous with regions subsequently allocated with , (comma) or ALLOT. See: 3.3.3.3 Variables.
– format and range of floating-point numbers (12.3.1 Data types, 12.6.1.2143 REPRESENT)
– results of 12.6.1.2143 REPRESENT when float is out of range;
– rounding or truncation of floating-point numbers (12.3.1.2 Floating-point numbers);
– size of floating-point stack (12.3.3 Floating-point stack);
– width of floating-point stack (12.3.3 Floating-point stack).
12.4.1.2 Ambiguous conditions
– no additional requirements.
12.4.1.4 Environmental restrictions
– requiring the floating-point stack to be larger than six items (12.3.3 Floating-point stack).
– requiring floating-point numbers to be kept on the data stack, with n cells per floating point number.
12.4.2.2 Other program documentation
– no additional requirements.
12.6 Glossary
12.6.1 Floating-Point words
12.6.1.0558 >FLOAT “to-float” FLOATING
( d – – ) ( F: – – r ) or ( d – – r )
r is the floating-point equivalent of d. An ambiguous condition exists if d cannot be
precisely represented as a floating-point value.
( f-addr – – ) ( F: r – – ) or ( r f-addr – – )
Store r at f-addr.
( F: r1 r2 – – r3 ) or ( r1 r2 – – r3 )
Multiply r1 by r2 giving r3.
( F: r1 r2 – – r3 ) or ( r1 r2 – – r3 )
Add r1 to r2 giving the sum r3.
( F: r1 r2 – – r3 ) or ( r1 r2 – – r3 )
Subtract r2 from r1, giving r3.
( F: r1 r2 – – r3 ) or ( r1 r2 – – r3 )
Divide r1 by r2, giving the quotient r3. An ambiguous condition exists if r2 is zero, or the
quotient lies outside of the range of a floating-point number.
( – – flag ) ( F: r – – ) or ( r – – flag )
flag is true if and only if r is less than zero.
( – – flag ) ( F: r – – ) or ( r – – flag )
flag is true if and only if r is equal to zero.
( – – flag ) ( F: r1 r2 – – ) or ( r1 r2 – – flag )
flag is true if and only if r1 is less than r2.
( – – d ) ( F: r – – ) or ( r – – d )
d is the double-cell signed-integer equivalent of the integer portion of r. The fractional
portion of r is discarded. An ambiguous condition exists if the integer portion of r cannot
be represented as a double-cell signed integer.
Note: Rounding the floating-point value prior to calling F>D is advised, because F>D rounds
towards zero.
( f-addr – – ) ( F: – – r ) or ( f-addr – – r )
r is the value stored at f-addr.
( –– )
If the data-space pointer is not float aligned, reserve enough data space to make it so.
( addr – – f-addr )
f-addr is the first float-aligned address greater than or equal to addr.
( “hspacesiname” – – ) ( F: r – – ) or ( r “hspacesiname” – – )
Skip leading space delimiters. Parse name delimited by a space. Create a definition for
name with the execution semantics defined below.
( – – +n )
+n is the number of values contained on the floating-point stack. If the system has an
environmental restriction of keeping the floating-point numbers on the data stack, +n is
the current number of possible floating-point values contained on the data stack.
( F: r – – ) or ( r – – )
Remove r from the floating-point stack.
( F: r – – r r ) or ( r – – r r )
Duplicate r.
( f-addr1 – – f-addr2 )
Add the size in address units of a floating-point number to f-addr1, giving f-addr2.
( n1 – – n2 )
n2 is the size in address units of n1 floating-point numbers.
( F: r1 – – r2 ) or ( r1 – – r2 )
Round r1 to an integral value using the “round toward negative infinity” rule, giving r2.
See: 12.3.2 Floating-point operations, 12.6.1.1612 FROUND, 12.6.2.1627 FTRUNC.
( F: r1 r2 – – r3 ) or ( r1 r2 – – r3 )
r3 is the greater of r1 and r2.
( F: r1 r2 – – r3 ) or ( r1 r2 – – r3 )
r3 is the lesser of r1 and r2.
( F: r1 – – r2 ) or ( r1 – – r2 )
r2 is the negation of r1.
( F: r1 r2 – – r1 r2 r1 ) or ( r1 r2 – – r1 r2 r1 )
Place a copy of r1 on top of the floating-point stack.
( F: r1 r2 r3 – – r2 r3 r1 ) or ( r1 r2 r3 – – r2 r3 r1 )
Rotate the top three floating-point stack entries.
( F: r1 – – r2 ) or ( r1 – – r2 )
Round r1 to an integral value using the “round to nearest” rule, giving r2.
See: 12.3.2 Floating-point operations, 12.6.1.1558 FLOOR, 12.6.2.1627 FTRUNC.
( F: r1 r2 – – r2 r1 ) or ( r1 r2 – – r2 r1 )
Exchange the top two floating-point stack items.
( “hspacesiname” – – )
Skip leading space delimiters. Parse name delimited by a space. Create a definition for
name with the execution semantics defined below. Reserve 1 FLOATS address units of
data space at a float-aligned address.
name is referred to as an “f-variable”.
name Execution: ( – – f-addr )
f-addr is the address of the data space reserved by FVARIABLE when it created name.
A program is responsible for initializing the contents of the reserved space.
See: 3.4.1 Parsing, A.12.6.1.1630 FVARIABLE.
( df-addr – – ) ( F: r – – ) or ( r df-addr – – )
Store the floating-point number r as a 64-bit IEEE double-precision number at df-addr.
If the significand of the internal representation of r has more precision than the IEEE
double-precision format, it will be rounded using the “round to nearest” rule. An am-
biguous condition exists if the exponent of r is too large to be accommodated in IEEE
double-precision format.
See: 12.3.1.1 Addresses, 12.3.2 Floating-point operations.
( df-addr – – ) ( F: – – r ) or ( df-addr – – r )
Fetch the 64-bit IEEE double-precision number stored at df-addr to the floating-point
stack as r in the internal representation. If the IEEE double-precision significand has
more precision than the internal representation it will be rounded to the internal repre-
sentation using the “round to nearest” rule. An ambiguous condition exists if the expo-
nent of the IEEE double-precision representation is too large to be accommodated by the
internal representation.
See: 12.3.1.1 Addresses, 12.3.2 Floating-point operations.
( –– )
If the data-space pointer is not double-float aligned, reserve enough data space to make
it so.
See: 12.3.1.1 Addresses.
( addr – – df-addr )
df-addr is the first double-float-aligned address greater than or equal to addr.
See: 12.3.1.1 Addresses.
( n1 “hspacesiname” – – n2 )
Skip leading space delimiters. Parse name delimited by a space. Offset is the first double-
float aligned value greater than or equal to n1. n2 = offset + 1 double-float.
Create a definition for name with the execution semantics given below.
name Execution: ( addr1 – – addr2 )
Add the offset calculated during the compile-time action to addr1 giving the address
addr2.
See: 10.6.2.0135 +FIELD, 10.6.2.0763 BEGIN-STRUCTURE,
10.6.2.1336 END-STRUCTURE, A.10.6.2.1518 FIELD:.
( df-addr1 – – df-addr2 )
Add the size in address units of a 64-bit IEEE double-precision number to df-addr1,
giving df-addr2.
See: 12.3.1.1 Addresses.
( n1 – – n2 )
n2 is the size in address units of n1 64-bit IEEE double-precision numbers.
( F: r1 r2 – – r3 ) or ( r1 r2 – – r3 )
Raise r1 to the power r2, giving the product r3.
( – – ) ( F: r – – ) or ( r – – )
Display, with a trailing space, the top number on the floating-point stack using fixed-
point notation:
[-] hdigitsi.hdigits0i
An ambiguous condition exists if the value of BASE is not (decimal) ten or if the char-
acter string representation exceeds the size of the pictured numeric output string buffer.
See: 12.6.1.0558 >FLOAT, A.12.6.2.1427 F.
( – – n ) ( F: r – – ) or ( r – – n )
n is the single-cell signed-integer equivalent of the integer portion of r. The fractional
portion of r is discarded. An ambiguous condition exists if the integer portion of r cannot
be represented as a single-cell signed integer.
Note: Rounding the floating-point value prior to calling F>S is advised, because F>S rounds
towards zero.
See: 12.6.2.2175 S>F.
( F: r1 – – r2 ) or ( r1 – – r2 )
r2 is the absolute value of r1.
( F: r1 – – r2 ) or ( r1 – – r2 )
r2 is the principal radian angle whose cosine is r1. An ambiguous condition exists if
| r1 | is greater than one.
( F: r1 – – r2 ) or ( r1 – – r2 )
r2 is the floating-point value whose hyperbolic cosine is r1. An ambiguous condition
exists if r1 is less than one.
( F: r1 – – r2 ) or ( r1 – – r2 )
Raise ten to the power r1, giving r2.
( F: r1 – – r2 ) or ( r1 – – r2 )
r2 is the principal radian angle whose sine is r1. An ambiguous condition exists if | r1 | is
greater than one.
( F: r1 – – r2 ) or ( r1 – – r2 )
r2 is the floating-point value whose hyperbolic sine is r1.
( F: r1 – – r2 ) or ( r1 – – r2 )
r2 is the principal radian angle whose tangent is r1.
( F: r1 r2 – – r3 ) or ( r1 r2 – – r3 )
r3 is the principal radian angle (between -π and π) whose tangent is r1/r2. A system that
returns false for “-0E 0E 0E F~” shall return a value (approximating) −π when r1 =
0E and r2 is negative. An ambiguous condition exists if r1 and r2 are zero.
See: A.12.6.2.1489 FATAN2.
( F: r1 – – r2 ) or ( r1 – – r2 )
r2 is the floating-point value whose hyperbolic tangent is r1. An ambiguous condition
exists if r1 is outside the range of -1E0 to 1E0.
( F: r1 – – r2 ) or ( r1 – – r2 )
r2 is the cosine of the radian angle r1.
( F: r1 – – r2 ) or ( r1 – – r2 )
r2 is the hyperbolic cosine of r1.
( – – ) ( F: r – – ) or ( r – – )
Display, with a trailing space, the top number on the floating-point stack using engineer-
ing notation, where the significand is greater than or equal to 1.0 and less than 1000.0
and the decimal exponent is a multiple of three.
An ambiguous condition exists if the value of BASE is not (decimal) ten or if the char-
acter string representation exceeds the size of the pictured numeric output string buffer.
See: 6.1.0750 BASE, 12.3.2 Floating-point operations, 12.6.1.2143 REPRESENT.
( F: r1 – – r2 ) or ( r1 – – r2 )
Raise e to the power r1, giving r2.
( F: r1 – – r2 ) or ( r1 – – r2 )
Raise e to the power r1 and subtract one, giving r2.
See: A.12.6.2.1516 FEXPM1.
( n1 “hspacesiname” – – n2 )
Skip leading space delimiters. Parse name delimited by a space. Offset is the first float
aligned value greater than or equal to n1. n2 = offset + 1 float.
Create a definition for name with the execution semantics given below.
name Execution: ( addr1 – – addr2 )
Add the offset calculated during the compile-time action to addr1 giving the address
addr2.
See: 10.6.2.0135 +FIELD, 10.6.2.0763 BEGIN-STRUCTURE,
10.6.2.1336 END-STRUCTURE, A.10.6.2.1518 FIELD:.
( F: r1 – – r2 ) or ( r1 – – r2 )
r2 is the natural logarithm of r1. An ambiguous condition exists if r1 is less than or equal
to zero.
( F: r1 – – r2 ) or ( r1 – – r2 )
r2 is the natural logarithm of the quantity r1 plus one. An ambiguous condition exists if
r1 is less than or equal to negative one.
See: A.12.6.2.1554 FLNP1.
( F: r1 – – r2 ) or ( r1 – – r2 )
r2 is the base-ten logarithm of r1. An ambiguous condition exists if r1 is less than or
equal to zero.
( – – ) ( F: r – – ) or ( r – – )
Display, with a trailing space, the top number on the floating-point stack in scientific
notation: hsignificandihexponenti where:
hsignificandi := [-]hdigiti.hdigits0i
hexponenti := E[-]hdigitsi
An ambiguous condition exists if the value of BASE is not (decimal) ten or if the char-
acter string representation exceeds the size of the pictured numeric output string buffer.
See: 6.1.0750 BASE, 12.3.2 Floating-point operations, 12.6.1.2143 REPRESENT.
( F: r1 – – r2 ) or ( r1 – – r2 )
r2 is the sine of the radian angle r1.
( F: r1 – – r2 r3 ) or ( r1 – – r2 r3 )
r2 is the sine of the radian angle r1. r3 is the cosine of the radian angle r1.
See: A.12.6.2.1489 FATAN2.
( F: r1 – – r2 ) or ( r1 – – r2 )
r2 is the hyperbolic sine of r1.
( F: r1 – – r2 ) or ( r1 – – r2 )
r2 is the square root of r1. An ambiguous condition exists if r1 is less than zero.
( F: r1 – – r2 ) or ( r1 – – r2 )
r2 is the tangent of the radian angle r1. An ambiguous condition exists if cos(r1 ) is zero.
( F: r1 – – r2 ) or ( r1 – – r2 )
r2 is the hyperbolic tangent of r1.
( F: r1 – – r2 ) or ( r1 – – r2 )
Round r1 to an integral value using the “round towards zero” rule, giving r2.
See: 12.3.2 Floating-point operations, 12.6.1.1612 FROUND, 12.6.1.1558 FLOOR.
( F: r – – ) ( “hspacesiname” – – ) or ( r “hspacesiname” – – )
Skip leading space delimiters. Parse name delimited by a space. Create a definition for
name with the execution semantics defined below, with an initial value equal to r.
name is referred to as a “f-value”.
name Execution: ( F: – – r ) or ( – – r )
Place r on the floating point stack. The value of r is that given when name was created,
until the phrase “r TO name” is executed, causing a new value of r to be assigned to
name.
TO name Run-time: ( F: r – – ) or ( r – – )
Assign the value r to name.
See: 3.4.1 Parsing, 6.2.2295 TO
( – – flag ) ( F: r1 r2 r3 – – ) or ( r1 r2 r3 – – flag )
If r3 is positive, flag is true if the absolute value of (r1 minus r2) is less than r3.
If r3 is zero, flag is true if the implementation-dependent encoding of r1 and r2 are exactly
identical (positive and negative zero are unequal if they have distinct encodings).
If r3 is negative, flag is true if the absolute value of (r1 minus r2) is less than the absolute
value of r3 times the sum of the absolute values of r1 and r2.
See: A.12.6.2.1640 F~.
( –– u )
Return the number of significant digits currently used by F., FE., or FS. as u.
( n – – ) ( F: – – r ) or ( n – – r )
r is the floating-point equivalent of the single-cell value n. An ambiguous condition
exists if n can not be precisely represented as a floating-point value.
See: 12.6.2.1471 F>S.
( u –– )
Set the number of significant digits currently used by F., FE., or FS. to u.
( sf-addr – – ) ( F: r – – ) or ( r sf-addr – – )
Store the floating-point number r as a 32-bit IEEE single-precision number at sf-addr. If
the significand of the internal representation of r has more precision than the IEEE single-
precision format, it will be rounded using the “round to nearest” rule. An ambiguous
condition exists if the exponent of r is too large to be accommodated by the IEEE single-
precision format.
See: 12.3.1.1 Addresses, 12.3.2 Floating-point operations.
( sf-addr – – ) ( F: – – r ) or ( sf-addr – – r )
Fetch the 32-bit IEEE single-precision number stored at sf-addr to the floating-point
stack as r in the internal representation. If the IEEE single-precision significand has more
precision than the internal representation, it will be rounded to the internal representation
using the “round to nearest” rule. An ambiguous condition exists if the exponent of the
IEEE single-precision representation is too large to be accommodated by the internal
representation.
See: 12.3.1.1 Addresses, 12.3.2 Floating-point operations.
( –– )
If the data-space pointer is not single-float aligned, reserve enough data space to make it
so.
See: 12.3.1.1 Addresses.
( addr – – sf-addr )
sf-addr is the first single-float-aligned address greater than or equal to addr.
See: 12.3.1.1 Addresses.
( n1 “hspacesiname” – – n2 )
Skip leading space delimiters. Parse name delimited by a space. Offset is the first single-
float aligned value greater than or equal to n1. n2 = offset + 1 single-float.
Create a definition for name with the execution semantics given below.
name Execution: ( addr1 – – addr2 )
Add the offset calculated during the compile-time action to addr1 giving the address
addr2.
See: 10.6.2.0135 +FIELD, 10.6.2.0763 BEGIN-STRUCTURE,
10.6.2.1336 END-STRUCTURE, A.10.6.2.1518 FIELD:.
( sf-addr1 – – sf-addr2 )
Add the size in address units of a 32-bit IEEE single-precision number to sf-addr1, giving
sf-addr2.
See: 12.3.1.1 Addresses.
( n1 – – n2 )
n2 is the size in address units of n1 32-bit IEEE single-precision numbers.
See: 12.3.1.1 Addresses.
13.1 Introduction
13.2 Additional terms and notation
None.
The system, upon receipt of a sequence of local-identifier messages, shall take the following actions at
compile time:
a) Create temporary dictionary entries for each of the identifiers passed to (LOCAL), such that each
identifier will behave as a local. These temporary dictionary entries shall vanish at the end of the defi-
nition, denoted by ; (semicolon), ;CODE, or DOES>. The system need not maintain these identifiers
in the same way it does other dictionary entries as long as they can be found by normal diction-
ary searching processes. Furthermore, if the Search-Order word set is present, local identifiers shall
always be searched before any of the word lists in any definable search order, and none of the Search-
Order words shall change the locals’ privileged position in the search order. Local identifiers may
reside in mass storage.
b) For each identifier passed to (LOCAL), the system shall generate an appropriate code sequence that
does the following at execution time:
1) Allocate a storage resource adequate to contain the value of a local. The storage shall be
allocated in a way that does not preclude re-entrancy or recursion in the definition using the
local.
2) Initialize the value using the top item on the data stack. If more than one local is declared, the
top item on the stack shall be moved into the first local identified, the next item shall be moved
into the second, and so on.
The storage resource may be the return stack or may be implemented in other ways, such as in
registers. The storage resource shall not be the data stack. Use of locals shall not restrict use of the
data stack before or after the point of declaration.
c) Arrange that any of the legitimate methods of terminating execution of a definition, specifically ;
(semicolon), ;CODE, DOES> or EXIT, will release the storage resource allocated for the locals, if
any, declared in that definition. ABORT shall release all local storage resources, and CATCH / THROW
(if implemented) shall release such resources for all definitions whose execution is being terminated.
d) Separate sets of locals may be declared in defining words before DOES> for use by the defining
word, and after DOES> for use by the word defined.
A system implementing the Locals word set shall support the declaration of at least sixteen locals in a
definition.
13.3.3.2 Syntax restrictions
Immediate words in a program may use (LOCAL) to implement syntaxes for local declarations with the
following restrictions:
a) A program shall not compile any executable code into the current definition between the time
(LOCAL) is executed to identify the first local for that definition and the time of sending the single
required “last local” message;
b) The position in program source at which the sequence of (LOCAL) messages is sent, referred to
here as the point at which locals are declared, shall not lie within the scope of any control structure;
c) Locals shall not be declared until values previously placed on the return stack within the definition
have been removed;
d) After a definition’s locals have been declared, a program may place data on the return stack. How-
ever, if this is done, locals shall not be accessed until those values have been removed from the return
stack;
e) Words that return execution tokens, such as ’ (tick), [’], or FIND, shall not be used with local
names;
f) A program that declares more than sixteen locals in a single definition has an environmental depend-
ency;
g) Locals may be accessed or updated within control structures, including do-loops;
h) Local names shall not be referenced by POSTPONE and [COMPILE].
See: 3.4 The Forth text interpreter.
– no additional requirements.
– declaring more than sixteen locals in a single definition (13.3.3 Processing locals).
13.4.2.2 Other program documentation
– no additional requirements.
13.6 Glossary
13.6.1 Locals words
13.6.1.0086 (LOCAL) “paren-local-paren” LOCAL
name Execution: ( – – x )
Place the value currently assigned to name on the stack. An ambiguous condition exists
when name is executed while in interpretation state.
TO name Run-time: ( x – – )
Set name to the value x.
See: 2.2.5 BNF notation, 6.2.2405 VALUE, 6.2.2295 TO, A.13.6.2.2550 {:.
14.1 Introduction
14.2 Additional terms and notation
None.
14.6 Glossary
14.6.1 Memory-Allocation words
14.6.1.0707 ALLOCATE MEMORY
( u – – a-addr ior )
Allocate u address units of contiguous data space. The data-space pointer is unaffected
by this operation. The initial content of the allocated space is undefined.
If the allocation succeeds, a-addr is the aligned starting address of the allocated space
and ior is zero.
If the operation fails, a-addr does not represent a valid address and ior is the implement-
ation-defined I/O result code.
See: 6.1.1650 HERE, 14.6.1.1605 FREE, 14.6.1.2145 RESIZE.
( a-addr – – ior )
Return the contiguous region of data space indicated by a-addr to the system for later
allocation. a-addr shall indicate a region of data space that was previously obtained by
ALLOCATE or RESIZE. The data-space pointer is unaffected by this operation.
If the operation succeeds, ior is zero. If the operation fails, ior is the implementation-
defined I/O result code.
See: 6.1.1650 HERE, 14.6.1.0707 ALLOCATE, 14.6.1.2145 RESIZE.
15.1 Introduction
This optional word set contains words most often used during the development of applications.
– ending sequence for input following 15.6.2.0470 ;CODE and 15.6.2.0930 CODE;
– manner of processing input following 15.6.2.0470 ;CODE and 15.6.2.0930 CODE;
– search-order capability for 15.6.2.1300 EDITOR and 15.6.2.0740 ASSEMBLER (15.3.2 The Forth
dictionary);
– source and format of display by 15.6.1.2194 SEE.
– no additional requirements.
– no additional requirements.
The phrase “Requiring name(s) from the Programming-Tools Extensions word set” shall be appended to
the label of Standard Programs that require the system to provide portions of the Programming-Tools
Extensions word set.
The phrase “Requiring the Programming-Tools Extensions word set” shall be appended to the label of
Standard Programs that require the system to provide all of the Programming-Tools and Programming-
Tools Extensions word sets.
15.6 Glossary
15.6.1 Programming-Tools words
15.6.1.0220 .S “dot-s” TOOLS
( –– )
Copy and display the values currently on the data stack. The format of the display is
implementation-dependent.
.S may be implemented using pictured numeric output words. Consequently, its use
may corrupt the transient region identified by #>.
See: 3.3.3.6 Other transient regions, A.15.6.1.0220 .S.
( a-addr – – )
Display the value stored at a-addr.
? may be implemented using pictured numeric output words. Consequently, its use may
corrupt the transient region identified by #>.
See: 3.3.3.6 Other transient regions.
( addr u – – )
Display the contents of u consecutive addresses starting at addr. The format of the
display is implementation dependent.
DUMP may be implemented using pictured numeric output words. Consequently, its use
may corrupt the transient region identified by #>.
See: 3.3.3.6 Other transient regions.
( “hspacesiname” – – )
Display a human-readable representation of the named word’s definition. The source
of the representation (object-code decompilation, source block, etc.) and the particular
form of the display is implementation defined.
SEE may be implemented using pictured numeric output words. Consequently, its use
may corrupt the transient region identified by #>.
See: 3.3.3.6 Other transient regions, A.15.6.1.2194 SEE.
( –– )
List the definition names in the first word list of the search order. The format of the
display is implementation-dependent.
WORDS may be implemented using pictured numeric output words. Consequently, its
use may corrupt the transient region identified by #>.
See: 3.3.3.6 Other transient regions, A.15.6.1.2465 WORDS.
name Execution: ( i * x – – j * x )
Perform the machine code sequence that was generated following ;CODE.
See: 6.1.1250 DOES>, A.15.6.2.0470 ;CODE.
( –– )
Replace the first word list in the search order with the ASSEMBLER word list.
See: 16 The optional Search-Order word set.
( –– )
Return control to the host operating system, if any.
( “hspacesiname” – – )
Skip leading space delimiters. Parse name delimited by a space. Create a definition for
name, called a “code definition”, with the execution semantics defined below.
Subsequent characters in the parse area typically represent source code in a programming
language, usually some form of assembly language. Those characters are processed in
an implementation-defined manner, generating the corresponding machine code. The
process continues, refilling the input buffer as needed, until an implementation-defined
ending sequence is processed.
name Execution: ( i * x – – j * x )
Execute the machine code sequence that was generated following CODE.
See: 3.4.1 Parsing, A.15.6.2.0930 CODE.
( –– )
Replace the first word list in the search order with the EDITOR word list.
See: 16 The optional Search-Order word set.
( “hspacesiname” – – )
Skip leading space delimiters. Parse name delimited by a space. Find name, then delete
name from the dictionary along with all words added to the dictionary after name. An
ambiguous condition exists if name cannot be found.
If the Search-Order word set is present, FORGET searches the compilation word list. An
ambiguous condition exists if the compilation word list is deleted.
An ambiguous condition exists if FORGET removes a word required for correct execu-
tion.
Note: This word is obsolescent and is included as a concession to existing implementations.
See: 3.4.1 Parsing, A.15.6.2.1580 FORGET.
( nt – – x xt )
x xt represents the compilation semantics of the word nt. The returned xt has the stack ef-
fect ( i * x x – – j * x ) . Executing xt consumes x and performs the compilation semantics
of the word represented by nt.
See: A.15.6.2.1909.10 NAME>COMPILE, 15.6.2.2297 TRAVERSE-WORDLIST.
( nt – – xt | 0 )
xt represents the interpretation semantics of the word nt. If nt has no interpretation
semantics, NAME>INTERPRET returns 0.
Note: This standard does not define the interpretation semantics of some words, but systems
are allowed to do so.
See: 15.6.2.2297 TRAVERSE-WORDLIST.
( nt – – c-addr u )
NAME>STRING returns the name of the word nt in the character string c-addr u. The
case of the characters in the string is implementation-dependent. The buffer containing
c-addr u may be transient and valid until the next invocation of NAME>STRING. A
program shall not write into the buffer containing the resulting string.
See: 15.6.2.2297 TRAVERSE-WORDLIST.
( – – a-addr )
Extend the semantics of 6.1.2250 STATE to allow ;CODE to change the value in STATE.
A program shall not directly alter the contents of STATE.
See: 3.4 The Forth text interpreter, 6.1.0450 :, 6.1.0460 ;, 6.1.0670 ABORT,
6.1.2050 QUIT, 6.1.2250 STATE, 6.1.2500 [, 6.1.2540 ], 6.2.0455 :NONAME,
15.6.2.0470 ;CODE.
( “hspacesinewname” “hspacesioldname” – – )
For both strings skip leading space delimiters. Parse newname and oldname delimited
by a space. Create a definition for newname with the semantics defined below. Newname
may be the same as oldname; when looking up oldname, newname shall not be found.
An ambiguous conditions exists if oldname can not be found or IMMEDIATE is applied
to newname.
newname interpretation: ( i * x – – j * x )
Perform the interpretation semantics of oldname.
newname compilation: ( i * x – – j * x )
Perform the compilation semantics of oldname.
See: 6.1.1710 IMMEDIATE.
( i * x xt wid – – j * x )
Remove wid and xt from the stack. Execute xt once for every word in the wordlist wid,
passing the name token nt of the word to xt, until the wordlist is exhausted or until xt
returns false.
The invoked xt has the stack effect ( k * x nt – – l * x flag ) .
If flag is true, TRAVERSE-WORDLIST will continue with the next name, otherwise it
will return. TRAVERSE-WORDLIST does not put any items other than nt on the stack
when calling xt, so that xt can access and modify the rest of the stack.
TRAVERSE-WORDLIST may visit words in any order, with one exception: words with
the same name are called in the order newest-to-oldest (possibly with other words in
between).
An ambiguous condition exists if words are added to or deleted from the wordlist wid
during the execution of TRAVERSE-WORDLIST.
See: A.15.6.2.2297 TRAVERSE-WORDLIST, 15.6.2.1909.40 NAME>STRING,
15.6.2.1909.20 NAME>INTERPRET, 15.6.2.1909.10 NAME>COMPILE.
16.1 Introduction
16.2 Additional terms and notation
compilation word list: The word list into which new definition names are placed.
search order: A list of word lists specifying the order in which the dictionary will be searched.
See: 3.1 Data types, 3.4.2 Finding definition names, 3.4 The Forth text interpreter.
A program that requires more than eight word lists in the search order has an environmental dependency.
See: 3.4.2 Finding definition names.
– maximum number of word lists in the search order (16.3.3 Finding definition names, 16.6.1.2197
SET-ORDER);
– minimum search order (16.6.1.2197 SET-ORDER, 16.6.2.1965 ONLY).
16.4.1.2 Ambiguous conditions
– no additional requirements.
– requiring more than eight word-lists in the search order (16.3.3 Finding definition names).
16.4.2.2 Other program documentation
– no additional requirements.
16.6 Glossary
16.6.1 Search-Order words
16.6.1.1180 DEFINITIONS SEARCH
( –– )
Make the compilation word list the same as the first word list in the search order. Speci-
fies that the names of subsequent definitions will be placed in the compilation word list.
Subsequent changes in the search order will not affect the compilation word list.
See: 16.3.3 Finding definition names.
( – – wid )
Return wid, the identifier of the word list that includes all standard words provided by
the implementation. This word list is initially the compilation word list and is part of the
initial search order.
( – – wid )
Return wid, the identifier of the compilation word list.
( – – widn . . . wid1 n )
Returns the number of word lists n in the search order and the word list identifiers widn
. . . wid1 identifying these word lists. wid1 identifies the word list that is searched first,
and widn the word list that is searched last. The search order is unaffected.
( c-addr u wid – – 0 | xt 1 | xt -1 )
Find the definition identified by the string c-addr u in the word list identified by wid.
If the definition is not found, return zero. If the definition is found, return its execution
token xt and one (1) if the definition is immediate, minus-one (-1) otherwise.
See: A.16.6.1.2192 SEARCH-WORDLIST.
( wid – – )
Set the compilation word list to the word list identified by wid.
( widn . . . wid1 n – – )
Set the search order to the word lists identified by widn . . . wid1. Subsequently, word list
wid1 will be searched first, and word list widn searched last. If n is zero, empty the search
order. If n is minus one, set the search order to the implementation-defined minimum
search order. The minimum search order shall include the words FORTH-WORDLIST
and SET-ORDER. A system shall allow n to be at least eight.
( – – wid )
Create a new empty word list, returning its word list identifier wid. The new word list
may be returned from a pool of preallocated word lists or may be dynamically allocated
in data space. A system shall allow the creation of at least 8 new word lists in addition
to any provided as part of the system.
( –– )
Transform the search order consisting of widn, . . . wid2, wid1 (where wid1 is searched
first) into widn, . . . wid2, wid1, wid1. An ambiguous condition exists if there are too many
word lists in the search order.
( –– )
Transform the search order consisting of widn, . . . wid2, wid1 (where wid1 is searched
first) into widn, . . . wid2, widFORTH-WORDLIST.
( –– )
Set the search order to the implementation-defined minimum search order. The minimum
search order shall include the words FORTH-WORDLIST and SET-ORDER.
( –– )
Display the word lists in the search order in their search order sequence, from first
searched to last searched. Also display the word list into which new definitions will
be placed. The display format is implementation dependent.
ORDER may be implemented using pictured numeric output words. Consequently, its
use may corrupt the transient region identified by #>.
See: 3.3.3.6 Other transient regions.
( –– )
Transform the search order consisting of widn, . . . wid2, wid1 (where wid1 is searched
first) into widn, . . . wid2. An ambiguous condition exists if the search order was empty
before PREVIOUS was executed.
17.1 Introduction
17.2 Additional terms and notation
None.
– no additional options.
17.4.1.2 Ambiguous conditions
– no additional requirements.
– no additional dependencies.
17.4.2.2 Other program documentation
– no additional requirements.
The phrase “Providing name(s) from the String Extensions word set” shall be appended to the label of any
Standard System that provides portions of the String Extensions word set.
The phrase “Providing the String Extensions word set” shall be appended to the label of any Standard
System that provides all of the String and String Extensions word sets.
17.6 Glossary
17.6.1 String words
17.6.1.0170 -TRAILING “dash-trailing” STRING
( c-addr u1 – – c-addr u2 )
If u1 is greater than zero, u2 is equal to u1 less the number of spaces at the end of the
character string specified by c-addr u1. If u1 is zero or the entire string consists of spaces,
u2 is zero.
( c-addr1 u1 n – – c-addr2 u2 )
Adjust the character string at c-addr1 by n characters. The resulting character string,
specified by c-addr2 u2, begins at c-addr1 plus n characters and is u1 minus n characters
long.
See: A.17.6.1.0245 /STRING.
( c-addr u – – )
If u is greater than zero, store the character value for space in u consecutive character
positions beginning at c-addr.
( c-addr1 c-addr2 u – – )
If u is greater than zero, copy u consecutive characters from the data space starting at c-
addr1 to that starting at c-addr2, proceeding character-by-character from lower addresses
to higher addresses.
See: 17.6.1.0920 CMOVE>, A.17.6.1.0910 CMOVE.
( c-addr1 c-addr2 u – – )
If u is greater than zero, copy u consecutive characters from the data space starting at
c-addr1 to that starting at c-addr2, proceeding character-by-character from higher ad-
dresses to lower addresses.
See: 17.6.1.0910 CMOVE, A.17.6.1.0920 CMOVE>.
( c-addr1 u1 c-addr2 u2 – – n )
Compare the string specified by c-addr1 u1 to the string specified by c-addr2 u2. The
strings are compared, beginning at the given addresses, character by character, up to the
length of the shorter string or until a difference is found. If the two strings are identical,
n is zero. If the two strings are identical up to the length of the shorter string, n is minus-
one (-1) if u1 is less than u2 and one (1) otherwise. If the two strings are not identical up
to the length of the shorter string, n is minus-one (-1) if the first non-matching character
in the string specified by c-addr1 u1 has a lesser numeric value than the corresponding
character in the string specified by c-addr2 u2 and one (1) otherwise.
Run-time: ( – – c-addr2 u )
Return c-addr2 u describing a string consisting of the characters specified by c-addr1 u
during compilation. A program shall not alter the returned string.
See: A.17.6.1.2212 SLITERAL.
( c-addr1 u1 c-addr2 u2 – – )
Set the string c-addr1 u1 as the text to substitute for the substitution named by c-addr2
u2. If the substitution does not exist it is created. The program may then reuse the buffer
c-addr1 u1 without affecting the definition of the substitution.
Ambiguous conditions occur as follows:
– The substitution cannot be created.
– The name of a substitution contains the ‘%’ delimiter character.
REPLACES may allot data space and create a definition. This breaks the contiguity of
the current region and is not allowed during compilation of a colon definition
See: 3.3.3.2 Contiguous regions, 3.4.5 Compilation, 17.6.2.2255 SUBSTITUTE.
c) If the text is not a valid substitution name, the name with leading and trailing de-
limiters is passed unchanged to the output. The current number of substitutions is
not changed.
d) Parsing of the input string resumes after the trailing delimiter.
If after processing any pairs of delimiters, the residue of the input string contains a single
delimiter, the residue is passed unchanged to the output.
See: 17.6.2.2141 REPLACES, 17.6.2.2375 UNESCAPE, A.17.6.2.2255 SUBSTITUTE.
18.1 Introduction
This word set deals with variable width character encodings. It also works with fixed width encodings.
Since the standard specifies ASCII encoding for characters, only ASCII-compatible encodings may be
used. Because ASCII compatibility has so many benefits, most encodings actually are ASCII compatible.
The characters beyond the ASCII encoding are called “extended characters” (xchars).
All words dealing with strings shall handle xchars when the xchar word set is present. This includes
dictionary definitions. White space parsing does not have to treat code points greater than $20 as white
space.
An extended character (xchar) is the code point of a character within an extended character set; on the stack
it is a subset of u. Extended characters are stored in memory encoded as one or more primitive characters
(pchars).
ACCEPT as input editor may be aware of xchars to provide comfort like backspace or cursor movement.
Since Unicode input and display poses a number of challenges like input method editors for different lan-
guages, left-to-right and right-to-left writing, and most fonts contain only a subset of Unicode glyphs,
systems should document their capabilities. File IO and in-memory string handling should work transpar-
ently with xchars.
18.4.1.2 Ambiguous conditions
– the data in memory does not encode a valid xchar (18.6.1.2486.50 X-SIZE);
– the xchars value is outside the range of allowed code points of the current character set used.
– words improperly used outside 6.1.0490 <# and 6.1.0040 #> (18.6.2.2488.20 XHOLD).
18.4.1.3 Other system documentation
– no additional requirements.
The phrase “Requiring the Extended-Character Extensions word set” shall be appended to the label of
Standard Programs that require the system to provide all of the Extended-Character Exception and Extended-
Character Extensions word sets.
18.6 Glossary
18.6.1 Extended-Character words
18.6.1.2486.50 X-SIZE XCHAR
( xc-addr u1 – – u2 )
u2 is the number of pchars used to encode the first xchar stored in the string xc-addr u1.
To calculate the size of the xchar, only the bytes inside the buffer may be accessed. An
ambiguous condition exists if the xchar is incomplete or malformed.
( xchar – – )
Append the encoding of xchar to the dictionary.
See: 6.1.0860 C,.
( xchar – – u )
u is the number of pchars used to encode xchar in memory.
( xc-addr1 – – xc-addr2 )
Adds the size of the xchar stored at xc-addr1 to this address, giving xc-addr2.
See: 6.1.0897 CHAR+.
( xchar – – )
Prints an xchar on the terminal.
See: 6.1.1320 EMIT
( – – xchar )
Reads an xchar from the terminal. This will discard all input events up to the completion
of the xchar.
See: 6.1.1750 KEY.
( – – flag )
Flag is true when it’s possible to do XKEY without blocking. Subsequent KEY?, KEY,
EKEY?, and EKEY may be affected by XKEY?.
See: 10.6.1.1755 KEY?.
( xc-addr1 u1 – – xc-addr2 u2 )
Step forward by one xchar in the buffer defined by xc-addr1 u1. xc-addr2 u2 is the re-
maining buffer after stepping over the first xchar in the buffer.
( xc-addr u1 – – xc-addr u2 )
Examine the last xchar in the string xc-addr u1 — if the encoding is correct and it rep-
resents a full xchar, u2 equals u1, otherwise, u2 represents the string without the last
(garbled) xchar. -TRAILING-GARBAGE does not change this garbled xchar.
( “hspacesiname” – – xchar )
Skip leading space delimiters. Parse name delimited by a space. Put the value of its first
xchar onto the stack.
See: 6.1.0895 CHAR
( xc-addr u – – n )
n is the number of monospace ASCII characters that take the same space to display as the
xchar string xc-addr u; assuming a monospaced display font, i.e., xchar width is always
an integer multiple of the width of an ASCII character.
( xchar – – n )
n is the number of monospace ASCII characters that take the same space to display as
the xchar; i.e., xchar width is always an integer multiple of the width of an ASCII char.
( xc-addr1 – – xc-addr2 )
Goes backward from xc-addr1 until it finds an xchar so that the size of this xchar added
to xc-addr2 gives xc-addr1. There is an ambiguous condition when the encoding doesn’t
permit reliable backward stepping through the text.
( xchar – – )
Adds xchar to the picture numeric output string. An ambiguous condition exists if
XHOLD executes outside of a <# #> delimited number conversion.
See: 6.1.1670 HOLD.
( xc-addr u1 – – xc-addr u2 )
Search for the penultimate xchar in the string xc-addr u1. The string xc-addr u2 contains
all xchars of xc-addr u1, but the last. Unlike XCHAR-, X\STRING- can be implemented
in encodings where xchar boundaries can only reliably detected when scanning in for-
ward direction.
Annex A
(informative)
Rationale
A.1 Introduction
A.1.1 Purpose
A.1.2 Scope
When judging relative merits of proposed changes to the standard, the members of the committee were
guided by the following goals (listed in alphabetic order):
Consistency The standard provides a functionally complete set of words with minimal func-
tional overlap.
Cost of compliance This goal includes such issues as common practice, how much existing code
would be broken by the proposed change, and the amount of effort required to
bring existing applications and systems into conformity with the standard.
Efficiency Execution speed, memory compactness.
Portability Words chosen for inclusion should be free of system-dependent features.
Readability Forth definition names should clearly delineate their behavior. That behavior
should have an apparent simplicity which supports rapid understanding. Forth
should be easily taught and support readily maintained code.
Utility Be judged to have sufficiently essential functionality and frequency of use to be
deemed suitable for inclusion.
182
Forth 2012 A. Rationale
data field
In earlier standards, data fields were known as “parameter fields”.
On subroutine threaded Forth systems, everything is object code. There are no traditional code or
data fields. Only a word defined by CREATE or by a word that calls CREATE has a data field. Only
a data field defined via CREATE can be manipulated portably.
word set
This standard recognizes that some functions, while useful in certain application areas, are not suf-
ficiently general to justify requiring them in all Forth systems. Further, it is helpful to group Forth
words according to related functions. These issues are dealt with using the concept of word sets.
The “Core” word set contains the essential body of words in a Forth system. It is the only “required”
word set. Other word sets defined in this standard are optional additions to make it possible to
provide Standard Systems with tailored levels of functionality.
A.2.2 Notation
A.2.2.2 Stack notation
The use of -sys, orig, and dest data types in stack effect diagrams conveys two pieces of information.
First, it warns the reader that many implementations use the data stack in unspecified ways for those
purposes, so that items underneath on either the control-flow or data stacks are unavailable. Second, in
cases where orig and dest are used, explicit pairing rules are documented on the assumption that all systems
will implement that model so that its results are equivalent to employment of some stack, and that in fact
many implementations do use the data stack for this purpose. However, nothing in this standard requires
that implementations actually employ the data stack (or any other) for this purpose so long as the implied
behavior of the model is maintained.
183
A. Rationale Forth 2012
by an application.
When data are operated upon, the meaning of the result depends on the meaning assigned to the input
values. Some combinations of input values produce meaningless results: for instance, what meaning can
be assigned to the arithmetic sum of the ASCII representation of the character “A” and a TRUE flag?
The answer may be “no meaning”; or alternatively, that operation might be the first step in producing a
checksum. Context is the determiner.
The discipline of circumscribing meaning which a program may assign to various combinations of bit
patterns is sometimes called data typing. Many computer languages impose explicit data typing and have
compilers that prevent ill-defined operations.
Forth rarely explicitly imposes data-type restrictions. Still, data types implicitly do exist, and discipline is
required, particularly if portability of programs is a goal. In Forth, it is incumbent upon the programmer
(rather than the compiler) to determine that data are accurately typed.
This section attempts to offer guidance regarding de facto data typing in Forth.
A.3.1.2 Character types
The correct identification and proper manipulation of the character data type is beyond the purview of
Forth’s enforcement of data type by means of stack depth. Characters do not necessarily occupy the entire
width of their single stack entry with meaningful data. While the distinction between signed and unsigned
character is entirely absent from the formal specification of Forth, the tendency in practice is to treat
characters as short positive integers when mathematical operations come into play.
a) Standard Character Set
1) The storage unit for the character data type (C@, C!, FILL, etc.) must be able to contain
unsigned numbers from 0 through 255.
2) An implementation is not required to restrict character storage to that range, but a Standard Pro-
gram without environmental dependencies cannot assume the ability to store numbers outside
that range in a “char” location.
3) The allowed number representations are two’s-complement, one’s-complement, and signed-
magnitude. Note that all of these number systems agree on the representation of positive num-
bers.
4) Since a “char” can store small positive numbers and since the character data type is a sub-
range of the unsigned integer data type, C! must store the n least-significant bits of a cell
(8 <= n <= bits/cell). Given the enumeration of allowed number representations and their
known encodings, “TRUE xx C! xx C@” must leave a stack item with some number of bits set,
which will thus will be accepted as non-zero by IF.
5) For the purposes of input (KEY, ACCEPT, etc.) and output (EMIT, TYPE, etc.), the encoding
between numbers and human-readable symbols is ISO646/IRV (ASCII) within the range from
32 to 126 (space to ~). EBCDIC is out (most “EBCDIC” computer systems support ASCII too).
Outside that range, it is up to the implementation. The obvious implementation choice is to use
ASCII control characters for the range from 0 to 31, at least for the “displayable” characters
in that range (TAB, RETURN, LINEFEED, FORMFEED). However, this is not as clear-cut
184
Forth 2012 A. Rationale
as it may seem, because of the variation between operating systems on the treatment of those
characters. For example, some systems TAB to 4 character boundaries, others to 8 character
boundaries, and others to preset tab stops. Some systems perform an automatic linefeed after
a carriage return, others perform an automatic carriage return after a linefeed, and others do
neither.
The codes from 128 to 255 may eventually be standardized, either formally or informally,
for use as international characters, such as the letters with diacritical marks found in many
European languages. One such encoding is the 8-bit ISO Latin-1 character set. The computer
marketplace at large will eventually decide which encoding set of those characters prevails. For
Forth implementations running under an operating system (the majority of those running on
standard platforms these days), most Forth implementors will probably choose to do whatever
the system does, without performing any remapping within the domain of the Forth system
itself.
6) A Standard Program can depend on the ability to receive any character in the range 32 . . .
126 through KEY, and similarly to display the same set of characters with EMIT. If a program
must be able to receive or display any particular character outside that range, it can declare an
environmental dependency on the ability to receive or display that character.
7) A Standard Program cannot use control characters in definition names. However, a Standard
System is not required to enforce this prohibition. Thus, existing systems that currently allow
control characters in words names from BLOCK source may continue to allow them, and pro-
grams running on those systems will continue to work. In text file source, the parsing action
with space as a delimiter (e.g., BL WORD) treats control characters the same as spaces. This
effectively implies that you cannot use control characters in definition names from text-file
source, since the text interpreter will treat the control characters as delimiters. Note that this
“control-character folding” applies only when space is the delimiter, thus the phrase “CHAR )
WORD” may collect a string containing control characters.
Characters are transferred from the data stack to memory by C! and from memory to the data stack
by C@. A number of lower-significance bits equivalent to the implementation-dependent width of a
character are transferred from a popped data stack entry to an address by the action of C! without
affecting any bits which may comprise the higher-significance portion of the cell at the destination
address; however, the action of C@ clears all higher-significance bits of the data stack entry which
it pushes that are beyond the implementation-dependent width of a character (which may include
implementation-defined display information in the higher-significance bits). The programmer should
keep in mind that operating upon arbitrary stack entries with words intended for the character data
type may result in truncation of such data.
In addition to C@ and C!, characters are moved to, from and upon the data stack by the following
words:
>R ?DUP DROP DUP OVER PICK R> R@ ROLL ROT SWAP
185
A. Rationale Forth 2012
d) Additional operations
+ - * / /MOD MOD
The following comparison and bitwise operators may be valid for characters, keeping in mind that
display information cached in the most significant bits of characters in an implementation-defined
fashion may have to be masked or otherwise dealt with:
AND OR > < U> U< = <> 0= 0<> MAX MIN LSHIFT RSHIFT
A single-cell stack entry viewed without regard to typing is the fundamental data type of Forth. All other
data types are actually represented by one or more single-cell stack entries.
Single-cell data are transferred from the stack to memory by !; from memory to the stack by @. All
bits are transferred in both directions and no type checking of any sort is performed, nor does the
Standard System check that a memory address used by ! or @ is properly aligned or properly sized
to hold the datum thus transferred.
Here is a selection of the most important words which move single-cell data to, from and upon the
data stack:
! @ >R ?DUP DROP DUP OVER PICK R> R@ ROLL ROT SWAP
c) Comparison operators
The following comparison operators are universally valid for one or more single cells:
= <> 0= 0<>
A.3.1.3.1 Flags
A FALSE flag is a single-cell datum with all bits unset, and a TRUE flag is a single-cell datum with all bits
set. While Forth words which test flags accept any non-null bit pattern as true, there exists the concept of
the well-formed flag. If an operation whose result is to be used as a flag may produce any bit-mask other
than TRUE or FALSE, the recommended discipline is to convert the result to a well-formed flag by means
of the Forth word 0<> so that the result of any subsequent logical operations on the flag will be predictable.
In addition to the words which move, fetch and store single-cell items, the following words are valid for
operations on one or more flag data residing on the data stack:
186
Forth 2012 A. Rationale
A.3.1.3.2 Integers
A single-cell datum may be treated by a Standard Program as a signed integer. Moving and storing such
data is performed as for any single-cell data. In addition to the universally-applicable operators for single-
cell data specified above, the following mathematical and comparison operators are valid for single-cell
signed integers:
* */ */MOD /MOD MOD + +! - / 1+ 1- ABS MAX MIN NEGATE 0< 0> < >
Given the same number of bits, unsigned integers usually represent twice the number of absolute values
representable by signed integers.
A single-cell datum may be treated by a Standard Program as an unsigned integer. Moving and storing
such data is performed as for any single-cell data. In addition, the following mathematical and comparison
operators are valid for single-cell unsigned integers:
UM* UM/MOD + +! - 1+ 1- * U< U>
A.3.1.3.3 Addresses
An address is uniquely represented as a single cell unsigned number and can be treated as such when being
moved to, from, or upon the stack. Conversely, each unsigned number represents a unique address (which
is not necessarily an address of accessible memory). This one-to-one relationship between addresses and
unsigned numbers forces an equivalence between address arithmetic and the corresponding operations on
unsigned numbers.
Several operators are provided specifically for address arithmetic:
CHAR+ CHARS CELL+ CELLS
and, if the floating-point word set is present:
FLOAT+ FLOATS SFLOAT+ SFLOATS DFLOAT+ DFLOATS
A Standard Program may never assume a particular correspondence between a Forth address and the phys-
ical address to which it is mapped.
187
A. Rationale Forth 2012
’ 1+ and
’ CHAR+
might return the same value.
Traditionally, Forth has been implemented on two’s-complement machines where there is a one-to-one
mapping of signed numbers to unsigned numbers — any single cell item can be viewed either as a signed
or unsigned number. Indeed, the signed representation of any positive number is identical to the equivalent
188
Forth 2012 A. Rationale
unsigned representation. Further, addresses are treated as unsigned numbers: there is no distinct pointer
type. Arithmetic ordering on two’s complement machines allows + and - to work on both signed and
unsigned numbers. This arithmetic behavior is deeply embedded in common Forth practice.
As a consequence of these behaviors, the likely ranges of signed and unsigned numbers for implementations
hosted on each of the permissible arithmetic architectures is:
Arithmetic architecture signed numbers unsigned numbers
Two’s complement −n − 1 to n 0 to 2n + 1
One’s complement −n to n 0 to n
Signed magnitude −n to n 0 to n
where n is the largest positive signed number. For all three architectures, signed numbers in the 0 to
n range are bitwise identical to the corresponding unsigned number. Note that unsigned numbers on a
signed magnitude machine are equivalent to signed non-negative numbers as a consequence of the forced
correspondence between addresses and unsigned numbers and of the required behavior of + and -.
For reference, these number representations may be defined by the way that NEGATE is implemented:
two’s complement: : NEGATE INVERT 1+ ;
one’s complement: : NEGATE INVERT ;
signed-magnitude: : NEGATE HIGH-BIT XOR ;
where HIGH-BIT is a bit mask with only the most-significant bit set. Note that all of these number systems
agree on the representation of non-negative numbers.
Per 3.2.1.1 Internal number representation and 6.1.0270 0=, the implementor must ensure that no stand-
ard or supported word return negative zero for any numeric (non-Boolean or flag) result. Many existing
programmer assumptions will be violated otherwise.
There is no requirement to implement circular unsigned arithmetic, nor to set the range of unsigned num-
bers to the full size of a cell. There is historical precedent for limiting the range of u to that of +n, which
is permissible when the cell size is greater than 16 bits.
189
A. Rationale Forth 2012
This compromise protects the investment made in current Forth applications; Forth-79 and Forth-83 pro-
grams are automatically compliant with Forth 94 with respect to division. In practice, the rounding direc-
tion rarely matters to applications. However, if a program requires a specific rounding direction, it can use
the floored division primitive FM/MOD or the symmetric division primitive SM/REM to construct a divi-
sion operator of the desired flavor. This simple technique can be used to convert Forth-79 and Forth-83
programs to Forth 94 without any analysis of the original programs.
A.3.2.3 Stacks
The only data type in Forth which has concrete rather than abstract existence is the stack entry. Even this
primitive typing Forth only enforces by the hard reality of stack underflow or overflow. The programmer
must have a clear idea of the number of stack entries to be consumed by the execution of a word and the
number of entries that will be pushed back to a stack by the execution of a word. The observation of
anomalous occurrences on the data stack is the first line of defense whereby the programmer may recog-
nize errors in an application program. It is also worth remembering that multiple stack errors caused by
erroneous application code are frequently of equal and opposite magnitude, causing complementary (and
deceptive) results.
For these reasons and a host of other reasons, the one unambiguous, uncontroversial, and indispensable
programming discipline observed since the earliest days of Forth is that of providing a stack diagram for
all additions to the application dictionary with the exception of static constructs such as VARIABLEs and
CONSTANTs.
A.3.2.3.2 Control-flow stack The simplest use of control-flow words is to implement the basic control
structures shown in figure A.1.
In control flow every branch, or transfer of control, must terminate at some destination. A natural im-
plementation uses a stack to remember the origin of forward branches and the destination of backward
190
Forth 2012 A. Rationale
branches. At a minimum, only the location of each origin or destination must be indicated, although other
implementation-dependent information also may be maintained.
An origin is the location of the branch itself. A destination is where control would continue if the branch
were taken. A destination is needed to resolve the branch address for each origin, and conversely, if every
control-flow path is completed no unused destinations can remain.
With the addition of just three words (AHEAD, CS-ROLL and CS-PICK), the basic control-flow words
supply the primitives necessary to compile a variety of transportable control structures. The abilities re-
quired are compilation of forward and backward conditional and unconditional branches and compile-time
management of branch origins and destinations. Table A.1 shows the desired behavior.
The requirement that control-flow words are properly balanced by other control-flow words makes reason-
able the description of a compile-time implementation-defined control-flow stack. There is no prescription
as to how the control-flow stack is implemented, e.g., data stack, linked list, special array. Each element of
the control-flow stack mentioned above is the same size.
With these tools, the remaining basic control-structure elements, shown in figure A.2, can be defined. The
stack notation used here for immediate words is ( compilation / execution ).
: WHILE ( dest -- orig dest / flag -- )
\ conditional exit from loops
POSTPONE IF \ conditional forward brach
1 CS-ROLL \ keep dest on top
; IMMEDIATE
191
A. Rationale Forth 2012
Forth control flow provides a solution for well-known problems with strictly structured programming.
The basic control structures can be supplemented, as shown in the examples in figure A.3, with additional
WHILEs in BEGIN . . . UNTIL and BEGIN . . . WHILE . . . REPEAT structures. However, for each
additional WHILE there must be a THEN at the end of the structure. THEN completes the syntax with
WHILE and indicates where to continue execution when the WHILE transfers control. The use of more
than one additional WHILE is possible but not common. Note that if the user finds this use of THEN
undesirable, an alias with a more likable name could be defined.
Additional actions may be performed between the control flow word (the REPEAT or UNTIL) and the
THEN that matches the additional WHILE. Further, if additional actions are desired for normal termination
and early termination, the alternative actions may be separated by the ordinary Forth ELSE. The termination
actions are all specified after the body of the loop.
Note that REPEAT creates an anomaly when matching the WHILE with ELSE or THEN, most notably when
compared with the BEGIN. . . UNTIL case. That is, there will be one less ELSE or THEN than there are
WHILEs because REPEAT resolves one THEN. As above, if the user finds this count mismatch undesirable,
REPEAT could be replaced in-line by its own definition.
Other loop-exit control-flow words, and even other loops, can be defined. The only requirements are that
the control-flow stack is properly maintained and manipulated.
The simple implementation of the CASE structure below is an example of control structure extension. Note
the maintenance of the data stack to prevent interference with the possible control-flow stack usage.
0 CONSTANT CASE IMMEDIATE ( init count of OFs )
192
Forth 2012 A. Rationale
1+ ( count OFs )
>R ( move off the stack in case the control-flow )
( stack is the data stack. )
POSTPONE OVER POSTPONE = ( copy and test case value)
POSTPONE IF ( add orig to control flow stack )
POSTPONE DROP ( discards case value if = )
R> ( we can bring count back now )
; IMMEDIATE
193
A. Rationale Forth 2012
LOOP
; IMMEDIATE
The size in address units of various data types may be determined by phrases such as 1 CHARS. Similarly,
alignment may be determined by phrases such as 1 ALIGNED.
The environmental queries are divided into two groups: those that always produce the same value and those
that might not. The former groups include entries such as MAX-N. This information is fixed by the hardware
or by the design of the Forth system; a user is guaranteed that asking the question once is sufficient.
The other, now obsolescent, group of queries are for things that may legitimately change over time. For
example an application might test for the presence of the Double Number word set using an environment
query. If it is missing, the system could invoke a system-dependent process to load the word set. The
system is permitted to change ENVIRONMENT?’s database so that subsequent queries about it indicate that
it is present.
Note that a query that returns an “unknown” response could produce a “known” result on a subsequent
query.
A.3.2.7 Obsolescent Environmental Queries
When reviewing the Forth 94 Standard, the question of adapting the word set queries had to be addressed.
Despite the recommendation in Forth 94, word set queries have not been supported in a meaningful way
by many systems. Consequently, these queries are not used by many programmers. The committee was
unwilling to exacerbate the problem by introducing additional queries for the revised word sets. The
committee has therefore declared the word set environment queries (see table 3.6) as obsolescent with the
intention of removing them altogether in the next revision. They are retained in this standard to support
existing Forth 94 programs. New programs should not use them.
A.3.2.8 Extension queries
194
Forth 2012 A. Rationale
programs will be somehow lacking or inferior because they are not standard; some of the finest jewels
of the programmer’s art will be non-standard. At the same time, the committee is trying to ensure that a
program labeled “Standard” will meet certain expectations, particularly with regard to portability.
In many system environments the input source is unable to supply certain non-graphic characters due to ex-
ternal factors, such as the use of those characters for flow control or editing. In addition, when interpreting
from a text file, the parsing function specifically treats non-graphic characters like spaces; thus words re-
ceived by the text interpreter will not contain embedded non-graphic characters. To allow implementations
in such environments to call themselves standard, this minor restriction on Standard Programs is necessary.
A Standard System is allowed to permit the creation of definition names containing non-graphic characters.
Historically, such names were used for keyboard editing functions and “invisible” words.
A.3.3.2 Code space
The words >IN, BASE, BLK, SCR, SOURCE, SOURCE-ID, STATE contain information used by the Forth
system in its operation and may be of use to the application. Any assumption made by the application
about data available in the Forth system it did not store other than the data just listed is an environmental
dependency.
There is no point in specifying (in the Standard) both what is and what is not addressable. A Standard
Program may NOT address:
– Directly into the data or return stacks;
– Into a definition’s data field if not stored by the application.
The read-only restrictions arise because some Forth systems run from ROM and some share I/O buffers
with other users or systems. Portable programs cannot know which areas are affected, hence the general
restrictions.
195
A. Rationale Forth 2012
The “initiation semantics” correspond to the code that is executed upon entering a definition, analogous
to the code executed by EXIT upon leaving a definition. The “run-time semantics” correspond to code
fragments, such as literals or branches, that are compiled inside colon definitions by words with explicit
compilation semantics.
196
Forth 2012 A. Rationale
In a Forth cross compiler, the execution semantics may be specified to occur in the host system only, the
target system only, or in both systems. For example, it may be appropriate for words such as CELLS to
execute on the host system returning a value describing the target, for colon definitions to execute only on
the target, and for CONSTANT and VARIABLE to have execution behaviors on both systems. Details of
cross compiler behavior are beyond the scope of this standard.
For a variety of reasons, this standard does not define interpretation semantics for every word. Examples of
these words are >R, .", DO, and IF. Nothing in this Standard precludes an implementation from providing
interpretation semantics for these words, such as interactive control-flow words. However, a Standard
Program may not use them in interpretation state.
A.3.4.5 Compilation
Compiler recursion at the definition level consumes excessive resources, especially to support locals. The
committee does not believe that the benefits justify the costs. Nesting definitions is also not common
practice and won’t work on many systems.
Section 5.1 defines the criteria that a system must meet in order to justify the label “Forth-2012 System”.
Briefly, the minimum requirement is that the system must “implement” the Core word set. There are
several ways in which this requirement may be met. The most obvious is that all Core words may be in a
pre-compiled kernel. This is not the only way of satisfying the requirement, however. For example, some
words may be provided in source blocks or files with instructions explaining how to add them to the system
if they are needed. So long as the words are provided in such a way that the user can obtain access to them
with a clear and straightforward procedure, they may be considered to be present.
A Forth cross compiler has many characteristics in common with a standard system, in that both use
similar compiling tools to process a program. However, in order to fully specify a Forth-2012 standard
cross compiler it would be necessary to address complex issues dealing with compilation and execution
semantics in both host and target environments as well as ROMability issues. The level of effort to do this
properly has proved to be impractical at this time. As a result, although it may be possible for a Forth cross
compiler to correctly prepare a Forth-2012 standard program for execution in a target environment, it is
inappropriate for a cross compiler to be labeled a Forth-2012 standard system.
197
A. Rationale Forth 2012
A.6 Glossary
In this and following sections we present rationales for the handling of specific words: why we included
them, why we placed them in certain word sets, or why we specified their names or meaning as we did.
Words in this section are organized by word set, retaining their index numbers for easy cross-referencing
to the glossary.
Historically, many Forth systems have been written in Forth. Many of the words in Forth originally had
as their primary purpose support of the Forth system itself. For example, WORD and FIND are often used
as the principle instruments of the Forth text interpreter, and CREATE in many systems is the primitive for
building dictionary entries. In defining words such as these in a standard way, we have endeavored not to
do so in such a way as to preclude their use by implementors. One of the features of Forth that has endeared
it to its users is that the same tools that are used to implement the system are available to the application
programmer — a result of this approach is the compactness and efficiency that characterizes most Forth
implementations.
A.6.1.0070 ’
Typical use: . . . ’ name.
Many Forth systems use a state-smart tick. Many do not. Forth-2012 follows the usage of Forth 94.
See: A.3.4.3.2 Interpretation semantics, A.6.1.1550 FIND.
A.6.1.0080 (
Typical use: . . . ( ccc) . . .
198
Forth 2012 A. Rationale
A.6.1.0140 +LOOP
Typical use: : X . . . limit first DO . . . step +LOOP ;
A.6.1.0150 ,
The use of , (comma) for compiling execution tokens is not portable.
See: 6.2.0945 COMPILE,.
A.6.1.0190 ."
Typical use: : X . . . ." ccc" . . . ;
An implementation may define interpretation semantics for ." if desired. In one plausible imple-
mentation, interpreting ." would display the delimited message. In another plausible implement-
ation, interpreting ." would compile code to display the message later. In still another plausible
implementation, interpreting ." would be treated as an exception. Given this variation a Stand-
ard Program may not use ." while interpreting. Similarly, a Standard Program may not compile
POSTPONE ." inside a new word, and then use that word while interpreting.
A.6.1.0450 :
Typical use: : name . . . ;
In Forth 83, this word was specified to alter the search order. This specification is explicitly removed
in this standard. We believe that in most cases this has no effect; however, systems that allow many
search orders found the Forth-83 behavior of colon very undesirable.
Note that colon does not itself invoke the compiler. Colon sets compilation state so that later words
in the parse area are compiled.
A.6.1.0460 ;
Typical use: : name . . . ;
One function performed by both ; and ;CODE is to allow the current definition to be found in the
dictionary. If the current definition was created by :NONAME the current definition has no definition
name and thus cannot be found in the dictionary. If :NONAME is implemented the Forth compiler
must maintain enough information about the current definition to allow ; and ;CODE to determine
whether or not any action must be taken to allow it to be found.
A.6.1.0550 >BODY
a-addr is the address that HERE would have returned had it been executed immediately after the
execution of the CREATE that defined xt.
A.6.1.0680 ABORT"
Typical use: : X . . . test ABORT" ccc" . . . ;
A.6.1.0695 ACCEPT
Specification of a non-zero, positive integer count (+n1) for ACCEPT allows some implementors to
continue their practice of using a zero or negative value as a flag to trigger special behavior. Insofar as
such behavior is outside the standard, Standard Programs cannot depend upon it, but the committee
doesn’t wish to preclude it unnecessarily. Because actual values are almost always small integers, no
functionality is impaired by this restriction.
199
A. Rationale Forth 2012
It is recommended that all non-graphic characters be reserved for editing or control functions and
not be stored in the input string.
Because external system hardware and software may perform the ACCEPT function, when a line
terminator is received the action of the cursor, and therefore the display, is implementation-defined. It
is recommended that the cursor remain immediately following the entered text after a line terminator
is received.
A.6.1.0705 ALIGN
In this standard we have attempted to provide transportability across various CPU architectures. One
of the frequent causes of transportability problems is the requirement of cell-aligned addresses on
some CPUs. On these systems, ALIGN and ALIGNED may be required to build and traverse data
structures built with C,. Implementors may define these words as no-ops on systems for which they
aren’t functional.
A.6.1.0760 BEGIN
Typical use:
: X . . . BEGIN . . . test UNTIL ;
or
: X . . . BEGIN . . . test WHILE . . . REPEAT ;
A.6.1.0770 BL
Because space is used throughout Forth as the standard delimiter, this word is the only way a program
has to find and use the system value of “space”. The value of a space character can not be obtained
with CHAR, for instance.
A.6.1.0880 CELL+
As with ALIGN and ALIGNED, the words CELLS and CELL+ were added to aid in transportability
across systems with different cell sizes. They are intended to be used in manipulating indexes and
addresses in integral numbers of cell-widths. Example:
2VARIABLE DATA
0 100 DATA 2!
DATA @ . 100
DATA CELL+ @ . 0
A.6.1.0890 CELLS
Example:
CREATE NUMBERS 100 CELLS ALLOT
Allots space in the array NUMBERS for 100 cells of data.
A.6.1.0895 CHAR
Typical use: . . . CHAR A CONSTANT "A" . . .
200
Forth 2012 A. Rationale
A.6.1.0950 CONSTANT
Typical use: . . . DECIMAL 10 CONSTANT TEN . . .
A.6.1.1000 CREATE
The data-field address of a word defined by CREATE is given by the data-space pointer immediately
following the execution of CREATE.
Reservation of data field space is typically done with ALLOT.
Typical use: . . . CREATE SOMETHING . . .
A.6.1.1240 DO
Typical use:
: X . . . limit first DO . . . LOOP ;
or
: X . . . limit first DO . . . step +LOOP ;
A.6.1.1250 DOES>
Typical use: : X . . . DOES> . . . ;
Following DOES>, a Standard Program may not make any assumptions regarding the ability to find
either the name of the definition containing the DOES> or any previous definition whose name may
be concealed by it. DOES> effectively ends one definition and begins another as far as local variables
and control-flow structures are concerned. The compilation behavior makes it clear that the user is
not entitled to place DOES> inside any control-flow structures.
A.6.1.1310 ELSE
Typical use: : X . . . test IF . . . ELSE . . . THEN ;
A.6.1.1345 ENVIRONMENT?
In a Standard System that contains only the Core word set, effective use of ENVIRONMENT? requires
either its use within a definition, or the use of user-supplied auxiliary definitions. The Core word set
lacks both a direct method for collecting a string in interpretation state (11.6.1.2165 S" is in an
optional word set) and also a means to test the returned flag in interpretation state (e.g. the optional
15.6.2.2532 [IF]).
A.6.1.1380 EXIT
Typical use: : X . . . test IF . . . EXIT THEN . . . ;
A.6.1.1550 FIND
One of the more difficult issues which the committee took on was the problem of divorcing the
specification of implementation mechanisms from the specification of the Forth language. Three
basic implementation approaches can be quickly enumerated:
1) Threaded code mechanisms. These are the traditional approaches to implementing Forth, but
other techniques may be used.
2) Subroutine threading with “macro-expansion” (code copying). Short routines, like the code for
DUP, are copied into a definition rather than compiling a JSR reference.
201
A. Rationale Forth 2012
3) Native coding with optimization. This may include stack optimization (replacing such phrases
as SWAP ROT + with one or two machine instructions, for example), parallelization (the trend
in the newer RISC chips is to have several functional subunits which can execute in parallel),
and so on.
The initial requirement (inherited from Forth 83) that compilation addresses be compiled into the
dictionary disallowed type 2 and type 3 implementations.
Type 3 mechanisms and optimizations of type 2 implementations were hampered by the explicit
specification of immediacy or non-immediacy of all standard words. POSTPONE allowed de-spec-
ification of immediacy or non-immediacy for all but a few Forth words whose behavior must be
STATE-independent.
One type 3 implementation, Charles Moore’s cmForth, has both compiling and interpreting versions
of many Forth words. At the present, this appears to be a common approach for type 3 implement-
ations. The committee felt that this implementation approach must be allowed. Consequently, it is
possible that words without interpretation semantics can be found only during compilation, and other
words may exist in two versions: a compiling version and an interpreting version. Hence the values
returned by FIND may depend on STATE, and ’ and [’] may be unable to find words without
interpretation semantics.
A.6.1.1561 FM/MOD
By introducing the requirement for “floored” division, Forth 83 produced much controversy and
concern on the part of those who preferred the more common practice followed in other languages
of implementing division according to the behavior of the host CPU, which is most often symmetric
(rounded toward zero). In attempting to find a compromise position, this standard provides primitives
for both common varieties, floored and symmetric (see SM/REM). FM/MOD is the floored version.
The committee considered providing two complete sets of explicitly named division operators, and
declined to do so on the grounds that this would unduly enlarge and complicate the standard. In-
stead, implementors may define the normal division words in terms of either FM/MOD or SM/REM
providing they document their choice. People wishing to have explicitly named sets of operators are
encouraged to do so. FM/MOD may be used, for example, to define:
: /_MOD ( n1 n2 -- n3 n4) >R S>D R> FM/MOD ;
: /_ ( n1 n2 -- n3) /_MOD SWAP DROP ;
: _MOD ( n1 n2 -- n3) /_MOD DROP ;
: */_MOD ( n1 n2 n3 -- n4 n5) >R M* R> FM/MOD ;
: */_ ( n1 n2 n3 -- n4 ) */_MOD SWAP DROP ;
A.6.1.1700 IF
Typical use:
: X . . . test IF . . . THEN . . . ;
or
: X . . . test IF . . . ELSE . . . THEN . . . ;
202
Forth 2012 A. Rationale
A.6.1.1710 IMMEDIATE
Typical use: : X . . . ; IMMEDIATE
A.6.1.1720 INVERT
The word NOT was originally provided in Forth as a flag operator to make control structures readable.
Under its intended usage the following two definitions would produce identical results:
: ONE ( flag -- )
IF ." true" ELSE ." false" THEN ;
: TWO ( flag -- )
NOT IF ." false" ELSE ." true" THEN ;
This was common usage prior to the Forth-83 Standard which redefined NOT as a cell-wide one’s-
complement operation, functionally equivalent to the phrase -1 XOR. At the same time, the data type
manipulated by this word was changed from a flag to a cell-wide collection of bits and the standard
value for true was changed from “1” (rightmost bit only set) to “-1” (all bits set). As these definitions
of TRUE and NOT were incompatible with their previous definitions, many Forth users continue to
rely on the old definitions. Hence both versions are in common use.
Therefore, usage of NOT cannot be standardized at this time. The two traditional meanings of NOT
— that of negating the sense of a flag and that of doing a one’s complement operation — are made
available by 0= and INVERT, respectively.
A.6.1.1730 J
J may only be used with a nested DO . . . LOOP, DO . . . +LOOP, ?DO . . . LOOP, or ?DO . . . +LOOP,
for example, in the form:
: X . . . DO . . . DO . . . J . . . LOOP . . . +LOOP . . . ;
A.6.1.1750 KEY
Use of KEY indicates that the application is processing primitive characters. Some input devices,
e.g., keyboards, may provide more information than can be represented as a primitive character and
such an event may be received as an implementation-specific sequence of primitive characters.
See A.10.6.2.1305 EKEY.
A.6.1.1760 LEAVE
Note that LEAVE immediately exits the loop. No words following LEAVE within the loop will be
executed. Typical use:
: X . . . DO . . . IF . . . LEAVE THEN . . . LOOP . . . ;
A.6.1.1780 LITERAL
Typical use: : X . . . [ x ] LITERAL . . . ;
A.6.1.1800 LOOP
Typical use:
: X . . . limit first DO . . . LOOP . . . ;
or
: X . . . limit first ?DO . . . LOOP . . . ;
203
A. Rationale Forth 2012
A.6.1.1810 M*
This word is a useful early step in calculation, going to extra precision conveniently. It has been in
use since the Forth systems of the early 1970’s.
A.6.1.1900 MOVE
CMOVE and CMOVE> are the primary move operators in Forth 83. They specify a behavior for moving
that implies propagation if the move is suitably invoked. In some hardware, this specific behavior
cannot be achieved using the best move instruction. Further, CMOVE and CMOVE> move characters;
Forth needs a move instruction capable of dealing with address units. Thus MOVE has been defined
and added to the Core word set, and CMOVE and CMOVE> have been moved to the String word set.
A.6.1.2033 POSTPONE
Typical use:
: ENDIF POSTPONE THEN ; IMMEDIATE
: X . . . IF . . . ENDIF . . . ;
POSTPONE replaces most of the functionality of COMPILE and [COMPILE]. COMPILE and
[COMPILE] are used for the same purpose: postpone the compilation behavior of the next word
in the parse area. COMPILE was designed to be applied to non-immediate words and [COMPILE]
to immediate words. This burdens the programmer with needing to know which words in a system
are immediate. Consequently, Forth standards have had to specify the immediacy or non-immediacy
of all words covered by the standard. This unnecessarily constrains implementors.
A second problem with COMPILE is that some programmers have come to expect and exploit a
particular implementation, namely:
: COMPILE R> DUP @ , CELL+ >R ;
This implementation will not work on native code Forth systems. In a native code Forth using inline
code expansion and peephole optimization, the size of the object code produced varies; this infor-
mation is difficult to communicate to a “dumb” COMPILE. A “smart” (i.e., immediate) COMPILE
would not have this problem, but this was forbidden in previous standards.
For these reasons, COMPILE has not been included in the standard and [COMPILE] has been moved
in favor of POSTPONE. Additional discussion can be found in Hayes, J.R., “Postpone”, Proceedings
of the 1989 Rochester Forth Conference.
A.6.1.2120 RECURSE
Typical use: : X . . . RECURSE . . . ;
This is Forth’s recursion operator; in some implementations it is called MYSELF. The usual example
is the coding of the factorial function.
: FACTORIAL ( +n1 -- +n2)
DUP 2 < IF DROP 1 EXIT THEN
DUP 1- RECURSE *
;
n2 = n1 (n1 − 1)(n1 − 2) · · · (2)(1), the product of n1 with all positive integers less than itself (as
a special case, zero factorial equals one). While beloved of computer scientists, recursion makes
204
Forth 2012 A. Rationale
unusually heavy use of both stacks and should therefore be used with caution. See alternate definition
in A.6.1.2140 REPEAT.
A.6.1.2140 REPEAT
Typical use:
A.6.1.2165 S"
Typical use: : X . . . S" ccc" . . . ;
A.6.1.2214 SM/REM
See the previous discussion of division under FM/MOD. SM/REM is the symmetric-division primitive,
which allows programs to define the following symmetric-division operators:
A.6.1.2216 SOURCE
SOURCE simplifies the process of directly accessing the input buffer by hiding the differences be-
tween its location for different input sources. This also gives implementors more flexibility in their
implementation of buffering mechanisms for different input sources. The committee moved away
from an input buffer specification consisting of a collection of individual variables.
A.6.1.2250 STATE
Although EVALUATE, LOAD, INCLUDE-FILE and INCLUDED are not listed as words which alter
STATE, the text interpreted by any one of these words could include one or more words which
explicitly alter STATE. EVALUATE, LOAD, INCLUDE-FILE and INCLUDED do not in themselves
alter STATE.
STATE does not nest with text interpreter nesting. For example, the code sequence:
will leave the system in compilation state. Similarly, after LOADing a block containing ], the system
will be in compilation state.
205
A. Rationale Forth 2012
Note that ] does not affect the parse area and that the only effect that : has on the parse area is to
parse a word. This entitles a program to use these words to set the state with known side-effects on
the parse area. For example:
: NOP : POSTPONE ; IMMEDIATE ;
NOP ALIGN
NOP ALIGNED
Some non-compliant systems have ] invoke a compiler loop in addition to setting STATE. Such a
system would inappropriately attempt to compile the second use of NOP.
A.6.1.2270 THEN
Typical use:
: X . . . test IF . . . THEN . . . ;
or
: X . . . test IF . . . ELSE . . . THEN . . . ;
A.6.1.2380 UNLOOP
Typical use:
: X ...
limit first DO
. . . test IF . . . UNLOOP EXIT THEN . . .
LOOP . . .
;
UNLOOP allows the use of EXIT within the context of DO . . . LOOP and related do-loop constructs.
UNLOOP as a function has been called UNDO. UNLOOP is more indicative of the action: nothing gets
undone — we simply stop doing it.
A.6.1.2390 UNTIL
Typical use: : X . . . BEGIN . . . test UNTIL . . . ;
A.6.1.2410 VARIABLE
Typical use: VARIABLE XYZ
A.6.1.2430 WHILE
Typical use: : X . . . BEGIN . . . test WHILE . . . REPEAT . . . ;
A.6.1.2450 WORD
Typical use: char WORD ccchchari
A.6.1.2500 [
Typical use: : X . . . [ 4321 ] LITERAL . . . ;
A.6.1.2510 [’]
Typical use: : X . . . [’] name . . . ;
See: A.6.1.1550 FIND.
206
Forth 2012 A. Rationale
A.6.1.2520 [CHAR]
Typical use: : X . . . [CHAR] c . . . ;
A.6.1.2540 ]
Typical use: : X . . . [ 4321 ] LITERAL . . . ;
:NONAME ( n -- ) . ; IS print
Note: RECURSE and DOES> are allowed within a :NONAME definition.
A.6.2.0620 ?DO
Typical use:
: X . . . ?DO . . . LOOP . . . ;
A.6.2.0700 AGAIN
Typical use: : X . . . BEGIN . . . AGAIN . . . ;
Unless word-sequence has a way to terminate, this is an endless loop.
207
A. Rationale Forth 2012
A.6.2.0825 BUFFER:
BUFFER: provides a means of defining an uninitialized buffer. In systems that use a single memory
space, this can effectively be defined as:
: BUFFER: ( u "<name>" -- ; -- addr )
CREATE ALLOT
;
However, many systems profit from a separation of uninitialized and initialized data areas. Such
systems can implement BUFFER: so that it allocates memory from a separate uninitialized memory
area. Embedded systems can take advantage of the lack of initialization of the memory area while
hosted systems are permitted to ALLOCATE a buffer. A system may select a region of memory for
performance reasons. A detailed knowledge of the memory allocation within the system is required
to provide a version of BUFFER: that can take advantage of the system.
It should be noted that the memory buffer provided by BUFFER: is not initialized by the system and
that if the application requires it to be initialized, it is the responsibility of the application to initialize
it.
A.6.2.0855 C"
Typical use: : X . . . C" ccc" . . . ;
See: A.3.1.3.4 Counted strings.
A.6.2.0873 CASE
Typical use:
: X ...
CASE
test1 OF . . . ENDOF
testn OF . . . ENDOF
. . . ( default )
ENDCASE . . .
;
A.6.2.0945 COMPILE,
COMPILE, is the compilation equivalent of EXECUTE.
In traditional threaded-code implementations, compilation is performed by , (comma). This usage
is not portable; it doesn’t work for subroutine-threaded, native code, or relocatable implementations.
Use of COMPILE, is portable.
In most systems it is possible to implement COMPILE, so it will generate code that is optimized
to the same extent as code that is generated by the normal compilation process. However, in some
implementations there are two different “tokens” corresponding to a particular definition name: the
normal “execution token” that is used while interpreting or with EXECUTE, and another “compilation
token” that is used while compiling. It is not always possible to obtain the compilation token from the
execution token. In these implementations, COMPILE, might not generate code that is as efficient
as normally compiled code.
The intention is that COMPILE, can be used as follows to write the classic interpreter/compiler loop:
208
Forth 2012 A. Rationale
... ( c-addr )
FIND ?DUP IF ( xt +-1 )
STATE @ IF ( xt +-1 )
0> IF EXECUTE ELSE COMPILE, THEN ( ??? )
ELSE ( xt +-1 )
DROP EXECUTE ( ??? )
THEN
ELSE ( c-addr )
( whatever you do for an undefined word )
THEN
...
Thus the interpretation semantics are left undefined, as COMPILE, will not be executed during
interpretation.
A.6.2.1342 ENDCASE
Typical use:
: X ...
CASE
test1 OF . . . ENDOF
testn OF . . . ENDOF
. . . ( default )
ENDCASE . . .
;
A.6.2.1343 ENDOF
Typical use:
: X ...
CASE
test1 OF . . . ENDOF
testn OF . . . ENDOF
. . . ( default )
ENDCASE . . .
;
A.6.2.1850 MARKER
As dictionary implementations have become more elaborate and in some cases have used multiple
address spaces, FORGET has become prohibitively difficult or impossible to implement on many
Forth systems. MARKER greatly eases the problem by making it possible for the system to remember
“landmark information” in advance that specifically marks the spots where the dictionary may at
some future time have to be rearranged.
A.6.2.1950 OF
Typical use:
: X ...
CASE
209
A. Rationale Forth 2012
test1 OF . . . ENDOF
testn OF . . . ENDOF
. . . ( default )
ENDCASE . . .
;
A.6.2.2000 PAD
PAD has been available as scratch storage for strings since the earliest Forth implementations. It was
brought to our attention that many programmers are reluctant to use PAD, fearing incompatibilities
with system uses. PAD is specifically intended as a programmer convenience, however, which is why
we documented the fact that no standard words use it.
A.6.2.2008 PARSE
Typical use: char PARSE ccchchari
The traditional Forth word for parsing is WORD. PARSE solves the following problems with WORD:
a) WORD always skips leading delimiters. This behavior is appropriate for use by the text inter-
preter, which looks for sequences of non-blank characters, but is inappropriate for use by words
like ( , .(, and .". Consider the following (flawed) definition of .(:
: .( [CHAR] ) WORD COUNT TYPE ; IMMEDIATE
This works fine when used in a line like:
.( HELLO) 5.
but consider what happens if the user enters an empty string:
.( ) 5.
The definition of .( shown above would treat the ) as a leading delimiter, skip it, and continue
consuming characters until it located another ) that followed a non-) character, or until the
parse area was empty. In the example shown, the 5 . would be treated as part of the string to
be printed.
With PARSE, we could write a correct definition of .(:
: .( [CHAR] ) PARSE TYPE ; IMMEDIATE
This definition avoids the “empty string” anomaly.
b) WORD returns its result as a counted string. This has four bad effects:
1) The characters accepted by WORD must be copied from the input buffer into a transient
buffer, in order to make room for the count character that must be at the beginning of the
counted string. The copy step is inefficient, compared to PARSE, which leaves the string
in the input buffer and doesn’t need to copy it anywhere.
2) WORD must be careful not to store too many characters into the transient buffer, thus over-
writing something beyond the end of the buffer. This adds to the overhead of the copy
step. (WORD may have to scan a lot of characters before finding the trailing delimiter.)
210
Forth 2012 A. Rationale
3) The count character limits the length of the string returned by WORD to 255 characters
(longer strings can easily be stored in blocks!). This limitation does not exist for PARSE.
4) The transient buffer is typically overwritten by the next use of WORD.
The need for WORD has largely been eliminated by PARSE and PARSE-NAME. WORD is re-
tained for backward compatibility.
A.6.2.2030 PICK
0 PICK is equivalent to DUP and 1 PICK is equivalent to OVER.
A.6.2.2125 REFILL
REFILL is designed to behave reasonably for all possible input sources. If the input source is
coming from the user, REFILL could still return a false value if, for instance, a communication
channel closes so that the system knows that no more input will be available.
A.6.2.2150 ROLL
2 ROLL is equivalent to ROT, 1 ROLL is equivalent to SWAP and 0 ROLL is a null operation.
A.6.2.2182 SAVE-INPUT
SAVE-INPUT and RESTORE-INPUT allow the same degree of input source repositioning within a
text file as is available with BLOCK input. SAVE-INPUT and RESTORE-INPUT “hide the details”
of the operations necessary to accomplish this repositioning, and are used the same way with all
input sources. This makes it easier for programs to reposition the input source, because they do not
have to inspect several variables and take different action depending on the values of those variables.
SAVE-INPUT and RESTORE-INPUT are intended for repositioning within a single input source;
for example, the following scenario is NOT allowed for a Standard Program:
: XX
SAVE-INPUT CREATE
S" RESTORE-INPUT" EVALUATE
ABORT" couldn’t restore input"
;
This is incorrect because, at the time RESTORE-INPUT is executed, the input source is the string
via EVALUATE, which is not the same input source that was in effect when SAVE-INPUT was
executed.
The following code is allowed:
: XX
SAVE-INPUT CREATE
S" .( Hello)" EVALUATE
RESTORE-INPUT ABORT" couldn’t restore input"
;
After EVALUATE returns, the input source specification is restored to its previous state, thus SAVE-
INPUT and RESTORE-INPUT are called with the same input source in effect.
In the above examples, the EVALUATE phrase could have been replaced by a phrase involving
INCLUDE-FILE and the same rules would apply.
211
A. Rationale Forth 2012
The standard does not specify what happens if a program violates the above rules. A Standard System
might check for the violation and return an exception indication from RESTORE-INPUT, or it might
fail in an unpredictable way.
The return value from RESTORE-INPUT is primarily intended to report the case where the program
attempts to restore the position of an input source whose position cannot be restored. The keyboard
might be such an input source.
Nesting of SAVE-INPUT and RESTORE-INPUT is allowed. For example, the following situation
works as expected:
: XX
SAVE-INPUT
S" f1" INCLUDED
\ The file "f1" includes:
\ ... SAVE-INPUT ... RESTORE-INPUT ...
\ End of file "f1"
RESTORE-INPUT ABORT" couldn’t restore input"
;
Such an implementation would not be useful in most cases. It would be preferable for a system to
leave SAVE-INPUT and RESTORE-INPUT undefined, rather than to create a useless implement-
ation. In the absence of the words, the application programmer could choose whether or not to create
“dummy” implementations or to work-around the problem in some other way.
Examples of how an implementation might use the return values from SAVE-INPUT to accomplish
the save/restore function:
Input Source possible stack values
block >IN @ BLK @ 2
EVALUATE >IN @ 1
keyboard >IN @ 1
text file >IN @ lo-pos hi-pos 3
These are examples only; a Standard Program may not assume any particular meaning for the indi-
vidual stack items returned by SAVE-INPUT.
A.6.2.2295 TO
Typical use: x TO name
Some implementations of TO do not parse; instead they set a mode flag that is tested by the subse-
quent execution of name. Standard programs must use TO as if it parses. Therefore TO and name
must be contiguous and on the same line in the source text.
212
Forth 2012 A. Rationale
A.6.2.2298 TRUE
TRUE is equivalent to the phrase 0 0=.
A.6.2.2405 VALUE
Typical use:
0 VALUE data
: EXCHANGE ( n1 -- n2 ) data SWAP TO data ;
EXCHANGE leaves n1 in data and returns the prior value n2.
A.6.2.2440 WITHIN
We describe WITHIN without mentioning circular number spaces (an undefined term) or providing
the code. Here is a number line with the overflow point (o) at the far right and the underflow point
(u) at the far left:
u o
There are two cases to consider: either the n2 | u2. . . n3 | u3 range straddles the overflow/underflow
points or it does not. Lets examine the non-straddle case first:
u [ ......... ) o
The [ denotes n2 | u2, the ) denotes n3 | u3, and the dots and [ are numbers WITHIN the range. n3 | u3
is greater than n2 | u2, so the following tests will determine if n1 | u1 is WITHIN n2 | u2 and n3 | u3:
n2 | u2 ≤ n1 | u1 and n1 | u1 < n3 | u3.
In the case where the comparison range straddles the overflow/underflow points:
u..........) [..........o
n3 | u3 is less than n2 | u2 and the following tests will determine if n1 | u1 is WITHIN n2 | u2 and
n3 | u3:
n2 | u2 ≤ n1 | u1 or n1 | u1 < n3 | u3.
WITHIN must work for both signed and unsigned arguments. One obvious implementation does not
work:
: WITHIN ( test low high -- flag )
>R OVER < 0= ( test flag1 ) SWAP R> < ( flag1 flag2 ) AND
;
Assume two’s-complement arithmetic on a 16-bit machine, and consider the following test:
33000 32000 34000 WITHIN
The above implementation returns false for that test, even though the unsigned number 33000 is
clearly within the range {{32000 . . . 34000}}.
The problem is that, in the incorrect implementation, the signed comparison < gives the wrong an-
swer when 32000 is compared to 33000, because when those numbers are treated as signed numbers,
33000 is treated as negative 32536, while 32000 remains positive.
213
A. Rationale Forth 2012
Replacing < with U< in the above implementation makes it work with unsigned numbers, but causes
problems with certain signed number ranges; in particular, the test:
1 -5 5 WITHIN
would give an incorrect answer.
For two’s-complement machines that ignore arithmetic overflow (most machines), the following
implementation works in all cases:
: WITHIN ( test low high -- flag ) OVER - >R - R> U< ;
A.6.2.2530 [COMPILE]
Typical use: : name2 . . . [COMPILE] name1 . . . ; IMMEDIATE
A.6.2.2535 \
Typical use:
5 CONSTANT THAT \ This is a comment about THAT
While the standard does not address multitasking per se, the items listed in 7.3.2 Block buffer regions that
may render block-buffer addresses invalid are due to multitasking considerations. The standard restricts
programs such that items that could fail on multitasking systems are not standard usage. It also permits
multitasking systems to be declared standard systems.
A.7.6 Glossary
A.7.6.2.2190 SCR
SCR is short for screen.
214
Forth 2012 A. Rationale
of 32-bits or more find that the necessity for double-length numbers is much diminished. Therefore, we
have factored the words that manipulate double-length entities into this optional word set.
Please note that the naming convention used in this word set conveys some important information:
1. Words whose names are of the form 2xxx deal with cell pairs, where the relationship between the
cells is unspecified. They may be two-vectors, double-length numbers, or any pair of cells that it is
convenient to manipulate together.
2. Words with names of the form Dxxx deal specifically with double-length integers.
3. Words with names of the form Mxxx deal with some combination of single and double integers. The
order in which these appear on the stack is determined by long-standing common practice.
Refer to A.3.1 for a discussion of data types in Forth.
A.8.6 Glossary
A.8.6.1.0360 2CONSTANT
Typical use: x1 x2 2CONSTANT name
A.8.6.1.0390 2LITERAL
Typical use: : X . . . [ x1 x2 ] 2LITERAL . . . ;
A.8.6.1.0440 2VARIABLE
Typical use: 2VARIABLE name
A.8.6.1.1070 D.R
In D.R, the “R” is short for RIGHT.
A.8.6.1.1140 D>S
There exist number representations, e.g., the sign-magnitude representation, where reduction from
double- to single-precision cannot simply be done with DROP. This word, equivalent to DROP on
two’s complement systems, desensitizes application code to number representation and facilitates
portability.
A.8.6.1.1820 M*/
M*/ was once described by Chuck Moore as the most useful arithmetic operator in Forth. It is the
main workhorse in most computations involving double-cell numbers. Note that some systems allow
signed divisors. This can cost a lot in performance on some CPUs. The requirement for a positive
divisor has not proven to be a problem.
A.8.6.1.1830 M+
M+ is the classical method for integrating.
A.8.6.2.0435 2VALUE
Typical use:
: fn1 S" filename" ;
fn1 2VALUE myfile
myfile INCLUDED
215
A. Rationale Forth 2012
The method of accomplishing this coupling is implementation dependent. For example, LOAD could
“know” about CATCH and THROW (by using CATCH itself, for example), or CATCH and THROW could
“know” about LOAD (by maintaining input source nesting information in a data structure known to THROW,
for example). Under these circumstances it is not possible for a Standard Program to define words such as
LOAD in a completely portable way.
A.9.6 Glossary
A.9.6.1.2275 THROW
If THROW is executed with a non zero argument, the effect is as if the corresponding CATCH had
returned it. In that case, the stack depth is the same as it was just before CATCH began execution.
The values of the i * x stack arguments could have been modified arbitrarily during the execution of
xt. In general, nothing useful may be done with those stack items, but since their number is known
216
Forth 2012 A. Rationale
(because the stack depth is deterministic), the application may DROP them to return to a predictable
stack state.
Typical use:
: could-fail ( -- char )
KEY DUP [CHAR] Q = IF 1 THROW THEN ;
: do-it ( a b -- c) 2DROP could-fail ;
: try-it ( --)
1 2 [’] do-it CATCH IF
( x1 x2 ) 2DROP ." There was an exception" CR
ELSE ." The character was " EMIT CR
THEN
;
; retry-it ( -- )
BEGIN 1 2 [’] do-it CATCH WHILE
( x1 x2) 2DROP ." Exception, keep trying" CR
REPEAT ( char )
." The character was " EMIT CR
;
217
A. Rationale Forth 2012
218
Forth 2012 A. Rationale
The standard currently defines an aligned field defining word for each of the standard data types:
CFIELD: a character
FIELD: a native integer (single cell)
FFIELD: a native float
SFFIELD: a 32 bit float
DFFIELD: a 64 bit float
Although this is a sufficient set, most systems provide facilities to define field defining words for
standard data types.
Future:
The following cannot be defined until the required addressing has been defined. The names should
be considered reserved until then.
BFIELD: 1 byte (8 bit) field
WFIELD: 16 bit field
LFIELD: 32 bit field
XFIELD: 64 bit field
A.10.6.2.1305 EKEY
For some input devices, such as keyboards, more information is available than can be returned by a
single execution of KEY. EKEY provides a standard word to access a system-dependent set of events.
EKEY and EKEY? are implementation specific; no assumption can be made regarding the interaction
between the pairs EKEY/EKEY? and KEY/KEY?. This standard does not define a timing relationship
between KEY? and EKEY?. Undefined results may be avoided by using only one pairing of KEY/
KEY? or EKEY/EKEY? in a program for each input stream.
EKEY assumes no particular numerical correspondence between particular event code values and
the values representing standard characters. On some systems, this may allow two separate keys
that correspond to the same standard character to be distinguished from one another. A standard
program may only interpret the results of EKEY via the translation words provided for that purpose
(EKEY>CHAR and EKEY>FKEY).
See: A.6.1.1750 KEY, 10.6.2.1306 EKEY>CHAR and 10.6.2.1306.40 EKEY>FKEY.
A.10.6.2.1306 EKEY>CHAR
EKEY>CHAR translates a keyboard event into the corresponding member of the character set, if such
a correspondence exists for that event.
It is possible that several different keyboard events may correspond to the same character, and other
keyboard events may correspond to no character.
A.10.6.2.1306.40 EKEY>FKEY
EKEY produces an abstract cell type for a keyboard event (e.g., a keyboard scan code). EKEY>FKEY
checks if such an event corresponds to a special (non-graphic) key press, and if so, returns a code
for the special key press. The encoding of special keys (returned by EKEY>FKEY) may be different
from the encoding of these keys as keyboard events (input to EKEY>FKEY).
Typical Use:
219
A. Rationale Forth 2012
. . . EKEY EKEY>FKEY IF
CASE
K-UP OF . . . ENDOF
K-F1 OF . . . ENDOF
K-LEFT K-SHIFT-MASK OR K-CTRL-MASK OR OF . . . ENDOF
...
ENDCASE
ELSE
...
THEN
The codes for the special keys are system-dependent, but this standard provides words for getting the
key codes for a number of keys:
Word Key Word Key
K-F1 F1 K-LEFT cursor left
K-F2 F2 K-RIGHT cursor right
K-F3 F3 K-UP cursor up
K-F4 F4 K-DOWN cursor down
K-F5 F5 K-HOME home or Pos1
K-F6 F6 K-END End
K-F7 F7 K-PRIOR PgUp or Prior
K-F8 F8 K-NEXT PgDn or Next
K-F9 F9 K-INSERT Insert
K-F10 F10 K-DELETE Delete
K-F11 F11
K-F12 F12
In addition, you can get codes for shifted variants of these keys by ORing with K-SHIFT-MASK,
K-CTRL-MASK and/or K-ALT-MASK, e.g. K-CTRL-MASK K-ALT-MASK OR K-DELETE OR.
The masks for the shift keys are:
Word Key
K-SHIFT-MASK Shift
K-CTRL-MASK Ctrl
K-ALT-MASK Alt
Note that not all of these keys are available on all systems, and not all combinations of keys and shift
keys are available. Therefore programs should be written such that they continue to work (although
less conveniently or with less functionality) if these key combinations cannot be produced.
A.10.6.2.1325 EMIT?
An indefinite delay is a device related condition, such as printer off-line, that requires operator inter-
vention before the device will accept new data.
A.10.6.2.1518 FIELD:
Create an aligned single-cell field in a data structure.
The various xFIELD: words provide for different alignment and size allocation.
220
Forth 2012 A. Rationale
Many systems reuse file identifiers; when a file is closed, a subsequently opened file may be given the same
identifier. If the original file has blocks still in block buffers, these will be incorrectly associated with the
newly opened file with disastrous results. The block buffer system must be flushed to avoid this.
A.11.3.4 Other transient regions
Additional transient buffers are provided for use by S" and S\". The buffers should be able to store two
consecutive strings, thus allowing the command line:
S" name1" S" name2" RENAME-FILE
The buffers may be implemented in a circular arrangement, where a string is placed into the next available
buffer. When there are no buffers available, the oldest buffer is overwritten.
S" and S\" may share the same buffers.
The list of words using memory in transient regions is extended to include 11.6.1.2165 S" and 11.6.2.2266
S\". See 3.3.3.6 Other transient regions.
A.11.6 Glossary
A.11.6.1.0765 BIN
Some operating systems require that files be opened in a different mode to access their contents as
an unstructured stream of binary data rather than as a sequence of lines.
The arguments to READ-FILE and WRITE-FILE are arrays of character storage elements, each
element consisting of at least 8 bits. The committee intends that, in BIN mode, the contents of these
storage elements can be written to a file and later read back without alteration.
221
A. Rationale Forth 2012
A.11.6.1.1010 CREATE-FILE
Typical use:
: X . . . S" TEST.FTH" R/W CREATE-FILE ABORT" CREATE-FILE FAILED" ;
A.11.6.1.1717 INCLUDE-FILE
Here are two implementation alternatives for saving the input source specification in the presence of
text file input:
1) Save the file position (as returned by FILE-POSITION) of the beginning of the line being
interpreted. To restore the input source specification, seek to that position and re-read the line
into the input buffer.
2) Allocate a separate line buffer for each active text input file, using that buffer as the input
buffer. This method avoids the “seek and reread” step, and allows the use of “pseudo-files”
such as pipes and other sequential-access-only communication channels.
A.11.6.1.1718 INCLUDED
Typical use: . . . S" filename" INCLUDED . . .
A.11.6.1.1970 OPEN-FILE
Typical use:
: X . . . S" TEST.FTH" R/W OPEN-FILE ABORT" OPEN-FILE FAILED" . . . ;
A.11.6.1.2080 READ-FILE
A typical sequential file-processing algorithm might look like:
BEGIN ( )
... READ-FILE THROW ( length )
?DUP WHILE ( length )
... ( )
REPEAT ( )
In this example, THROW is used to handle exception conditions, which are reported as non-zero values
of the ior return value from READ-FILE. End-of-file is reported as a zero value of the “length” return
value.
A.11.6.1.2090 READ-LINE
Implementations are allowed to store the line terminator in the memory buffer in order to allow the
use of line reading functions provided by host operating systems, some of which store the terminator.
Without this provision, a transient buffer might be needed. The two-character limitation is sufficient
for the vast majority of existing operating systems. Implementations on host operating systems
whose line terminator sequence is longer than two characters may have to take special action to
prevent the storage of more than two terminator characters.
Standard Programs may not depend on the presence of any such terminator sequence in the buffer.
A typical line-oriented sequential file-processing algorithm might look like:
BEGIN ( )
... READ-LINE THROW ( length not-eof-flag )
222
Forth 2012 A. Rationale
WHILE ( length )
... ( )
REPEAT DROP ( )
READ-LINE needs a separate end-of-file flag because empty (zero-length) lines are a routine occur-
rence, so a zero-length line cannot be used to signify end-of-file.
A.11.6.1.2165 S"
Typical use: . . . S" ccc" . . .
The interpretation semantics for S" are intended to provide a simple mechanism for entering a string
in the interpretation state. Since an implementation may choose to provide only one buffer for
interpreted strings, an interpreted string is subject to being overwritten by the next execution of S"
in interpretation state. It is intended that no standard words other than S" should in themselves
cause the interpreted string to be overwritten. However, since words such as EVALUATE, LOAD,
INCLUDE-FILE and INCLUDED can result in the interpretation of arbitrary text, possibly including
instances of S", the interpreted string may be invalidated by some uses of these words.
When the possibility of overwriting a string can arise, it is prudent to copy the string to a “safe”
buffer allocated by the application.
A.11.6.2.1714 INCLUDE
Typical use:
INCLUDE filename
A.11.6.2.2144.10 REQUIRE
Typical use:
REQUIRE filename
A.11.6.2.2144.50 REQUIRED
Typical use:
S" filename" REQUIRED
223
A. Rationale Forth 2012
In defining custom floating-point data structures, be aware that CREATE doesn’t necessarily leave the data
space pointer aligned for various floating-point data types. Programs may comply with the requirement for
the various kinds of floating-point alignment by specifying the appropriate alignment both at compile-time
and execution time. For example:
: FCONSTANT ( F: r -- )
CREATE FALIGN HERE 1 FLOATS ALLOT F!
DOES> ( F: -- r ) FALIGNED F@ ;
A.12.3.7 Text interpreter input number conversion
The committee has more than once received the suggestion that the text interpreter in standard Forth sys-
tems should treat numbers that have an embedded decimal point, but no exponent, as floating-point numbers
rather than double cell numbers. This suggestion, although it has merit, has always been voted down be-
cause it would break too much existing code; many existing implementations put the full digit string on
the stack as a double number and use other means to inform the application of the location of the decimal
point.
A.12.6 Glossary
A.12.6.1.0558 >FLOAT
>FLOAT enables programs to read floating-point data in legible ASCII format. It accepts a much
broader syntax than does the text interpreter since the latter defines rules for composing source
programs whereas >FLOAT defines rules for accepting data. >FLOAT is defined as broadly as is
feasible to permit input of data from Forth-2012 systems as well as other widely used standard
programming environments.
This is a synthesis of common FORTRAN practice. Embedded spaces are explicitly forbidden in
much scientific usage, as are other field separators such as comma or slash.
While >FLOAT is not required to treat a string of blanks as zero, this behavior is strongly encouraged,
since a future version of this standard may include such a requirement.
A.12.6.1.1492 FCONSTANT
Typical use: r FCONSTANT name
A.12.6.1.1552 FLITERAL
Typical use: : X . . . [ . . . ( r ) ] FLITERAL . . . ;
A.12.6.1.1630 FVARIABLE
Typical use: FVARIABLE name
A.12.6.1.2143 REPRESENT
This word provides a primitive for floating-point display. Some floating-point formats, including
those specified by IEEE-754, allow representations of numbers outside of an implementation-defined
range. These include plus and minus infinities, denormalized numbers, and others. In these cases we
224
Forth 2012 A. Rationale
expect that REPRESENT will usually be implemented to return appropriate character strings, such
as “+infinity” or “nan”, possibly truncated.
A.12.6.2.1427 F.
For example, 1E3 F. displays 1000.
A.12.6.2.1489 FATAN2
FSINCOS and FATAN2 are a complementary pair of operators which convert angles to 2-vectors
and vice-versa. They are essential to most geometric and physical applications since they correctly
and unambiguously handle this conversion in all cases except null vectors, even when the tangent of
the angle would be infinite.
FSINCOS returns a Cartesian unit vector in the direction of the given angle, measured counter-
clockwise from the positive X-axis. The order of results on the stack, namely y underneath x, permits
the 2-vector data type to be additionally viewed and used as a ratio approximating the tangent of the
angle. Thus the phrase FSINCOS F/ is functionally equivalent to FTAN, but is useful over only a
limited and discontinuous range of angles, whereas FSINCOS and FATAN2 are useful for all angles.
The argument order for FATAN2 is the same, converting a vector in the conventional representation
to a scalar angle. Thus, for all angles, FSINCOS FATAN2 is an identity within the accuracy of the
arithmetic and the argument range of FSINCOS. Note that while FSINCOS always returns a valid
unit vector, FATAN2 will accept any non-null vector. An ambiguous condition exists if the vector
argument to FATAN2 has zero magnitude.
A.12.6.2.1516 FEXPM1
This function allows accurate computation when its arguments are close to zero, and provides a useful
base for the standard exponential functions. Hyperbolic functions such as sinh(x) can be efficiently
and accurately implemented by using FEXPM1; accuracy is lost in this function for small values of x
if the word FEXP is used.
An important application of this word is in finance; say a loan is repaid at 15% per year; what is the
daily rate? On a computer with single-precision (six decimal digit) accuracy:
1. Using FLN and FEXP:
FLN of 1.15 = 0.139762,
divide by 365 = 3.82910E-4,
form the exponent using FEXP = 1.00038, and
subtract one (1) and convert to percentage = 0.038%.
Thus we only have two-digit accuracy.
2. Using FLNP1 and FEXPM1:
FLNP1 of 0.15 = 0.139762, (this is the same value as in the first example, although with the
argument closer to zero it may not be so)
divide by 365 = 3.82910E-4,
form the exponent and subtract one (1) using FEXPM1 = 3.82983E-4, and
convert to percentage = 0.0382983%.
225
A. Rationale Forth 2012
This calculation method allows the hyperbolic functions to be computed with six-digit accuracy. For
example, sinh can be defined as:
: FSINH ( r1 -- r2 )
FEXPM1 FDUP FDUP 1.0E0 F+ F/ F+ 2.0E0 F/ ;
A.12.6.2.1554 FLNP1
This function allows accurate compilation when its arguments are close to zero, and provides a useful
base for the standard logarithmic functions. For example, FLN can be implemented as:
: FLN 1.0E0 F- FLNP1 ;
See: A.12.6.2.1516 FEXPM1.
A.12.6.2.1640 F~
This provides the three types of “floating point equality” in common use — “close” in absolute terms,
exact equality as represented, and “relatively close”.
A.13.6 Glossary
A.13.6.2.2550 {:
The Forth 94 Technical Committee was unable to identify any common practice for locals. It pro-
vided a way to define locals and a method of parsing them in the hope that a common practice would
emerge.
226
Forth 2012 A. Rationale
Since then, common practice has emerged. Most implementations that provide (LOCAL) and
LOCALS| also provide some form of the { . . . } notation; however, the phrase { . . . } conflicts
with other systems. The {: . . . :} notation is a compromise to avoid name conflicts.
The notation provides for different kinds of local: those that are initialized from the data stack at
run-time, uninitialized locals, and outputs. Initialized locals are separated from uninitialized locals
by ‘|’. The definition of locals is terminated by ‘--’ or ‘:}’.
All text between ‘--’ and ‘:}’ is ignored. This eases documentation by allowing a complete stack
comment in the locals definition.
The ‘|’ (ASCII $7C) character is widely used as the separator between local arguments and local
values. Some implementations have used ‘\’ (ASCII $5C) or ‘¦’ ($A6). Systems are free to con-
tinue to provide these alternative separators. However, only the recognition of the ‘|’ separator is
mandatory. Therefore portable programs must use the ‘|’ separator.
A number of systems extend the locals notation in various ways. Some of these extensions may
emerge as common practice. This standard has reserved the notation used by these extensions to
avoid difficulties when porting code to these systems. In particular local names ending in ‘:’ (colon),
‘[’ (open bracket), or ‘^’ (caret) are reserved.
Name tokens are an abstract data type identifying named words. You can use words such as NAME>STRING
to get information out of name tokens.
227
A. Rationale Forth 2012
A.15.6 Glossary
A.15.6.1.0220 .S
.S is a debugging convenience found on almost all Forth systems. It is universally mentioned in
Forth texts.
A.15.6.1.2194 SEE
SEE acts as an on-line form of documentation of words, allowing modification of words by decom-
piling and regenerating with appropriate changes.
A.15.6.1.2465 WORDS
WORDS is a debugging convenience found on almost all Forth systems. It is universally referred to
in Forth texts.
A.15.6.2.0470 ;CODE
Typical use: : namex . . . hcreatei . . . ;CODE . . .
where namex is a defining word, and hcreatei is CREATE or any user defined word that calls
CREATE.
A.15.6.2.0930 CODE
Some Forth systems implement the assembly function by adding an ASSEMBLER word list to the
search order, using the text interpreter to parse a postfix assembly language with lexical characteris-
tics similar to Forth source code. Typically, in such systems, assembly ends when a word END-CODE
is interpreted.
A.15.6.2.1015 CS-PICK
The intent is to copy a dest on the control-flow stack so that it can be resolved more than once. For
example:
\ Conditionally transfer control to beginning of
\ loop. This is similar in spirit to C’s "continue"
\ statement.
: ?REPEAT ( dest -- dest ) \ Compilation
( flag -- ) \ Execution
0 CS-PICK POSTPONE UNTIL
; IMMEDIATE
: XX ( -- ) \ Example use of ?REPEAT
BEGIN
...
flag ?REPEAT ( Go back to BEGIN if flag is false )
...
flag ?REPEAT ( Go back to BEGIN if flag is false )
...
flag UNTIL ( Go back to BEGIN if flag is false )
;
228
Forth 2012 A. Rationale
A.15.6.2.1020 CS-ROLL
The intent is to modify the order in which the origs and dests on the control-flow stack are to be
resolved by subsequent control-flow words. For example, WHILE could be implemented in terms of
IF and CS-ROLL, as follows:
: WHILE ( dest -- orig dest )
POSTPONE IF 1 CS-ROLL
; IMMEDIATE
A.15.6.2.1580 FORGET
Typical use: . . . FORGET name . . .
FORGET name tries to infer the previous dictionary state from name; this is not always possible. As
a consequence, FORGET name removes name and all following words in the name space.
See A.6.2.1850 MARKER.
A.15.6.2.1908 N>R
An implementation may store the stack items in any manner. It may store them on the return stack,
in any order. A stack-constrained system may prefer to use a buffer to store the items and place a
reference to the buffer on the return stack.
See: 6.2.2182 SAVE-INPUT, 6.2.2148 RESTORE-INPUT, 16.6.1.1647 GET-ORDER,
16.6.1.2197 SET-ORDER.
A.15.6.2.1909.10 NAME>COMPILE
In a traditional xt+immediate-flag system, the x xt returned by NAME>COMPILE is typically xt1 xt2,
where xt1 is the xt of the word under consideration, and xt2 is the xt of EXECUTE (for immediate
words) or COMPILE, (for words with default compilation semantics).
If you want to POSTPONE nt, you can do so with
NAME>COMPILE SWAP POSTPONE LITERAL COMPILE,
A.15.6.2.2297 TRAVERSE-WORDLIST
Typical use:
: WORDS-COUNT ( x nt - x’ f ) DROP 1+ TRUE ;
0 ’ WORDS-COUNT FORTH-WORDLIST TRAVERSE-WORDLIST .
prints a count of the number of words in the FORTH-WORDLIST.
: ALL-WORDS NAME>STRING CR TYPE TRUE ;
’ ALL-WORDS GET-CURRENT TRAVERSE-WORDLIST
prints the names of words in the current compilation wordlist.
: CONTAINS-STRING
NAME>STRING 2OVER SEARCH IF CR TYPE THEN FALSE ;
S" COM" ’ CONTAINS-STRING GET-CURRENT TRAVERSE-WORDLIST
prints the name of a word containing the string “COM”, if it exists, and then terminates.
229
A. Rationale Forth 2012
A.15.6.2.2531 [ELSE]
Typical use: . . . flag [IF] . . . [ELSE] . . . [THEN] . . .
A.15.6.2.2532 [IF]
Typical use: . . . flag [IF] . . . [ELSE] . . . [THEN] . . .
A.15.6.2.2533 [THEN]
Typical use: . . . flag [IF] . . . [ELSE] . . . [THEN] . . .
Software that runs in several system environments often contains some source code that is environ-
mentally dependent. Conditional compilation — the selective inclusion or exclusion of portions of
the source code at compile time — is one technique that is often used to assist in the maintenance of
such source code.
Conditional compilation is sometimes done with “smart comments” — definitions that either skip or
do not skip the remainder of the line based on some test. For example:
VARIABLE 16-BIT?
This technique works on a line by line basis, and is good for short, isolated variant code sequences.
More complicated conditional compilation problems suggest a nestable method that can encompass
more than one source line at a time. The words included in the optional Programming tools exten-
sions word set are useful for this purpose.
The encoding for word list identifiers wid might be a small-integer index into an array of word-list defi-
nition records, the data-space address of such a record, a user-area offset, the execution token of a sealed
vocabulary, the link-field address of the first definition in a word list, or anything else. It is entirely up to
the system implementor.
search order
Note that the use of the term “list” does not necessarily imply implementation as a linked list
230
Forth 2012 A. Rationale
A.16.6 Glossary
A.16.6.1.2192 SEARCH-WORDLIST
When SEARCH-WORDLIST fails to find the word, it does not return the string, unlike FIND. This
is in accordance with the general principle that Forth words consume their arguments.
231
A. Rationale Forth 2012
A.17.6.1.2212 SLITERAL
The current functionality of 6.1.2165 S" may be provided by the following definition:
: S" ( "ccc<quote>" -- )
[CHAR] " PARSE POSTPONE SLITERAL
; IMMEDIATE
A.17.6.2.2255 SUBSTITUTE
Many applications need to be able to perform text substitution, for example:
Your balance at htimei on hdatei is hcurrencyvaluei.
Translation of a sentence or message from one language to another may result in changes to the dis-
played parameter order. The example, the Afrikaans translation of this sentence requires a different
order:
Jou balans op hdatei om htimei is hcurrencyvaluei.
The words SUBSTITUTE and REPLACES provide for this requirements by defining a text substitu-
tion facility. For example, we can provide an initial string in the form:
Your balance at %time% on %date% is %currencyvalue%.
The % is used as delimiters for the substitution name. The text “currencyvalue”, “date” and
“time” are text substitutions, where the replacement text is defined by REPLACES:
: date S" 10/Nov/2014" ;
: time S" 14:52" ;
date S" date" REPLACES
time S" time" REPLACES
The substitution name “date” is defined to be replaced with the string “10/Nov/2014” and “time” to
be replaced with “14:52”. Thus SUBSTITUTE would produce the string:
Your balance at 14:52 on 10/Nov/2014 is %currencyvalue%.
As the substitution name “currencyvalue” has not been defined, it is left unchanged in the resulting
string.
The return value n is nonnegative on success and indicates the number of substitutions made. In the
above example, this would be two. A negative value indicates that an error occurred. As substitution
is not recursive, the return value could be used to provide a recursive substitution.
Implementation of SUBSTITUTE may be considered as being equivalent to a wordlist which is
searched. If the substitution name is found, the word is executed, returning a substitution string. Such
words can be deferred or multiple wordlists can be used. The implementation techniques required
are similar to those used by ENVIRONMENT?. There is no provision for changing the delimiter
character, although a system may provide system-specific extensions.
232
Forth 2012 A. Rationale
a single byte is sufficient to encode all characters in each language, although different languages may use
different encodings; Latin-1 and Latin-15 are widely used. For other languages, different character sets
have to be used, several of which are variable-width. Currently, the most popular representative of the
variable-width character sets is UTF-8.
Many Forth systems today are case insensitive, to accept lower case standard words. It is sufficient to
be case insensitive for the ASCII subset to make this work — this saves a large code mapping table for
comparison of other symbols. Case is mostly an issue of European languages (Latin, Greek, and Cyrillic),
but similar issues exist between traditional and simplified Chinese (finally being dealt with by Unihan), and
between different Latin code pages in the Universal Character Set (UCS), e.g., full width vs. normal half
width Latin letters.
Furthermore, UCS allows composition of glyphs and has direct encoding for composed glyphs, which look
the same, but have different encodings. This is not a problem for a Forth system to solve.
Some encodings (not UTF-8) might give surprises when you use a case insensitive ASCII-compare that’s
8-bit safe, but not aware of the current encoding.
The xchar word set does not address problems that come from using multiple different encodings and
switching or converting between them. It is good practice for a system implementing xchar to support
UTF–8.
A.18.6 Glossary
A.18.6.2.0895 CHAR
The behavior of the extended version of CHAR is fully backward compatible with 6.1.0895 CHAR.
233
B. Bibliography Forth 2012
Annex B
(informative)
Bibliography
Industry standards
Forth-77 Standard, Forth Users Group, FST-780314.
Forth-78 Standard, Forth International Standards Team.
Forth-79 Standard, Forth Standards Team.
Forth-83 Standard and Appendices, Forth Standards Team.
The standards referenced in this section were developed by the Forth Standards Team, a volunteer
group which included both implementors and users. This was a volunteer organization operating
under its own charter and without any formal ties to ANSI, IEEE or any similar standards body.
The following standards where developed under the auspices of ANSI. The committee drawing up
the ANSI standard included several members of the Forth Standards Team.
ANSI X3.215-1994 Information Systems — Programming Language FORTH
ISO/IEC 15145:1997 Information technology. Programming languages. FORTH
Books
Brodie, L. Thinking FORTH. Englewood Cliffs, NJ: Prentice Hall, 1984. Now available from
http://thinking-forth.sourceforge.net/
Brodie, L. Starting FORTH (2nd edition). Englewood Cliffs, NJ: Prentice Hall, 1987.
Feierbach, G. and Thomas, P. Forth Tools & Applications. Reston, VA: Reston Computer Books,
1985.
Haydon, Dr. Glen B. All About FORTH (3rd edition). La Honda, CA: 1990.
Kelly, Mahlon G. and Spies, N. FORTH: A Text and Reference. Englewood Cliffs, NJ: Prentice
Hall, 1986.
Knecht, K. Introduction to Forth. Indiana: Howard Sams & Co., 1982.
Koopman, P. Stack Computers, The New Wave. Chichester, West Sussex, England: Ellis Horwood
Ltd. 1989.
Martin, Thea, editor. A Bibliography of Forth References (3rd edition). Rochester, New York:
Institute of Applied Forth Research, 1987.
McCabe, C. K. Forth Fundamentals (2 volumes). Oregon: Dilithium Press, 1983.
Ouverson, Marlin, editor. Dr. Dobbs Toolbook of Forth. Redwood City, CA: M&T Press, Vol. 1,
1986; Vol. 2, 1987.
Pelc, Stephen. Programming Forth. Southampton, England: MicroProcessor Engineering Limited,
2005. http://www.mpeforth.com/arena/ProgramForth.pdf.
Pountain, R. Object Oriented Forth. London, England: Academic Press, 1987.
234
Forth 2012 B. Bibliography
Rather, Elizabeth D. Forth Application Techniques. FORTH, Inc., 2006. ISBN: 978-0966215618.
Rather, Elizabeth D. and Conklin, Edward K. Forth Programmer’s Handbook (3rd edition).
BookSurge Publishing, 2007. ISBN: 978-1419675492.
Terry, J. D. Library of Forth Routines and Utilities. New York: Shadow Lawn Press, 1986.
Tracy, M. and Anderson, A. Mastering FORTH (revised edition). New York: Brady Books, 1989.
Winfield, A. The Complete Forth. New York: Wiley Books, 1983.
Journals, magazines and newsletters
Forsley, Lawrence P., Conference Chairman. Rochester Forth Conference Proceedings. Rochester,
New York: Institute of Applied Forth Research, 1981 to present.
Forsley, Lawrence P., Editor-in-Chief. The Journal of Forth Application and Research. Rochester,
New York: Institute of Applied Forth Research, 1983 to present.
Frenger, Paul, editor. SIGForth Newsletter. New York, NY: Association for Computing Machinery,
1989 to present.
Ouverson, Marlin, editor. Forth Dimensions. San Jose, CA: The Forth Interest Group, 1978 to
present.
Reiling, Robert, editor. FORML Conference Proceedings. San Jose, CA: The Forth Interest Group,
1980 to present.
Ting, Dr. C. H., editor. More on Forth Engines. San Mateo, CA: Offete Enterprises, 1986 to
present.
Selected articles
Hayes, J.R. “Postpone” Proceedings of the 1989 Rochester Forth Conference. Rochester, New
York: Institute for Applied Forth Research, 1989.
Kelly, Guy M. “Forth”. McGraw-Hill Personal Computer Programming Encyclopedia — Lan-
guages and Operation Systems. New York: McGraw-Hill, 1985.
Kogge, P. M. “An Architectural Trail to Threaded Code Systems”. IEEE Computer (March, 1982).
Moore, C. H. “The Evolution of FORTH — An Unusual Language”. Byte (August 1980).
Rather, E. D. “Forth Programming Language”. Encyclopedia of Physical Science & Technology
(Vol. 5). New York: Academic Press, 1987.
Rather, E. D. “FORTH”. Computer Programming Management. Auerbach Publishers, Inc., 1985.
Rather, E. D.; Colburn, D. R.; Moore, C. H. “The Evolution of Forth”. ACM SIGPLAN Notices
(Vol. 28, No. 3, March 1993).
235
C. Compatibility analysis Forth 2012
Annex C
(informative)
Compatibility analysis
Before this standard, there were several industry standards for Forth. The most influential are listed here in
chronological order, along with the major differences between this standard and the most recent, Forth 94.
C.2 Forth 79
The Forth-79 Standard resulted from a series of meetings from 1978 to 1980, by the Forth Standards Team,
an international group of Forth users and vendors (interim versions known as Forth 77 and Forth 78 were
also released by the group).
Forth 79 described a set of words defined on a 16-bit, twos-complement, unaligned, linear byte-addressing
virtual machine. It prescribed an implementation technique known as “indirect threaded code”, and used
the ASCII character set.
The Forth-79 Standard served as the basis for several public domain and commercial implementations,
some of which are still available and supported today.
C.3 Forth 83
The Forth-83 Standard, also by the Forth Standards Team, was released in 1983. Forth 83 attempted to fix
some of the deficiencies of Forth 79.
Forth 83 was similar to Forth 79 in most respects. However, Forth 83 changed the definition of several
well-defined features of Forth 79. For example, the rounding behavior of integer division, the base value
of the operands of PICK and ROLL, the meaning of the address returned by ’, the compilation behavior
of ’, the value of a “true” flag, the meaning of NOT, and the “chaining” behavior of words defined by
VOCABULARY were all changed. Forth 83 relaxed the implementation restrictions of Forth 79 to allow
236
Forth 2012 C. Compatibility analysis
any kind of threaded code, but it did not fully allow compilation to native machine code (this was not
specifically prohibited, but rather was an indirect consequence of another provision).
Many new Forth implementations were based on the Forth-83 Standard, but few “strictly compliant” Forth-
83 implementations exist.
Although the incompatibilities resulting from the changes between Forth 79 and Forth 83 were usually
relatively easy to fix, a number of successful Forth vendors did not convert their implementations to be
Forth 83 compliant. For example, the most successful commercial Forth for Apple Macintosh computers
is based on Forth 79.
237
C. Compatibility analysis Forth 2012
The ISO/IEC adopted the Forth 94 document as an international standard in 1997, publishing it under the
title “ISO/IEC 15145:1997 Information technology. Programming languages. FORTH”.
238
Forth 2012 C. Compatibility analysis
Previously systems could implement either a separate floating-point stack or a combined floating-point/data
stack; programs were required to cater for both (or declare an environmental dependency on a particular
variant).
Words Affected:
All floating-point words.
Reason:
The developing of software that may be used with either a combined stack or a separate stack is
extremely difficult and costly. While some of the systems surveyed provide a combined floating-
point/data stack, they all provide a separate floating-point stack.
Impact:
Forth 94 programs with an environmental dependency on a separate floating-point stack become
standard programs.
Forth 94 programs with an environmental dependency on a combined stack retain the environmental
dependency.
Forth 94 programs (without environmental dependency, i.e., those working on either kind of system)
remain standard programs.
Forth 94 systems that implement a separate floating-point stack continue to be standard systems.
Forth 94 systems that implement a combined stack become systems with an environmental restriction
of not providing a separate floating-point stack, but a combined stack.
Transition/Conversion:
Any code that has an environmental dependency on the use of a combined floating-point/data stack
should be ported to use a separate floating-point stack.
A system that has an environmental restriction on using a combined floating-point/data stack should
consider providing a separate floating-point stack.
With the advent of a new standard, it was necessary to review the meaning of word set queries. Compati-
bility with Forth 94 demands that a word set query produce the same result as for Forth 94; i.e., querying
for CORE-EXT returns true only if all the Forth 94 CORE EXT words are present. The question was how
to distinguish between word sets described by this and subsequent standards.
The committee considered adding a year indicator to the word set name (“CORE-EXT-2012”) or a pro-
viding a general query (“Forth-2012”) which could be combined with the word-set query. As the
committee could find very few examples of the word-set queries being used, it chose not to update the
word set-query mechanism, but rather to mark it as obsolescent.
Words Affected:
ENVIRONMENT?
239
C. Compatibility analysis Forth 2012
Reason:
The use of the word-set query to inquire whether a word set is present in the system has been marked
obsolescent. If present the query indicates the word set, as documented in Forth 94, is available.
Impact:
Forth 94 did not guarantee the presence of these queries. Many systems that provided all the words
in a particular word set did not provide the corresponding query. Portable programs are not affected
as they could not rely on this function.
Transition/Conversion:
There is no direct equivalent to determine the presence of a whole word set. The 15.6.2.2530.30
[DEFINED] and 15.6.2.2534 [UNDEFINED] words can be used to detect the availability (or oth-
erwise) of individual words.
6.2.2295 TO has been extended to act on targets defined with 12.6.2.1628 FVALUE and 8.6.2.0435 2VALUE.
Words affected:
TO
Words affected:
All words that return an ior.
Reason:
Forth 94 left the error code (ior) implementation-defined, although it did recommend an ior to be a
THROW code. Forth 2012 now requires an ior to be a THROW code.
Transition/Conversion:
Forth 94 programs are not affected. Programs that are dependent on iors being throwable are no
longer required to document the dependency.
Forth 94 systems that abided by the recommendation are not affected. Systems that did not heed
this advice are required to do so. A number of THROW codes were added to table 9.1 to ease this
transition.
Words affected:
(LOCAL), LOCALS|
Reason:
Some programs require more than eight locals.
Transition/Conversion:
Existing programs are unaffected. Systems implementing the locals word set have to be changed to
support at least 16 (previously 8) locals.
240
Forth 2012 C. Compatibility analysis
C.7.9 FASINH
An ambiguous condition on r1 being less than 0 was removed.
Existing programs are not affected. Existing systems are unlikely to be affected.
C.7.10 FATAN2
Words affected:
FATAN2
Reason:
The result is now specified more tightly: it is the principal angle (between -pi and pi).
Impact:
Forth 94 compliant programs are not affected.
Transition/Conversion:
Systems may have to change FATAN2 to return the principal angle.
241
C. Compatibility analysis Forth 2012
The following words have been added to 10.6.2 Facility extension words:
The following words have been added to 11.6.2 File-Access extension words:
The following words have been added to 12.6.2 Floating-Point extension words:
The following words have been added to 13.6.2 Locals extension words:
13.6.2.2550 {:
The following words have been added to the 15.6.2 Programming-Tools extension words:
The following words have been added to the 17.6.2 String extension words:
242
Forth 2012 C. Compatibility analysis
243
D. Portability guide Forth 2012
Annex D
(informative)
Portability guide
D.1 Introduction
A primary goal of Forth 94 was to enable a programmer to write Forth programs that work on a wide variety
of machines, Forth-2012 continues this practice. This goal is accomplished by allowing some key Forth
terms to be implementation defined (e.g., cell size) and by providing Forth operators (words) that conceal
the implementation. This allows the implementor to produce the Forth system that most effectively uses the
native hardware. The machine independent operators, together with some programmer discipline, support
program portability.
It can be difficult for someone familiar with only one machine architecture to imagine the problems
caused by transporting programs between dissimilar machines. This Annex provides guidelines for writing
portable Forth programs. The first section describes ways to make a program hardware independent.
The second section describes assumptions about Forth implementations that many programmers make, but
can’t be relied upon in a portable program.
D.2.2 Definitions
Three terms defined by this standard are address unit, cell, and character.
The address space of a Forth system is divided into an array of address units; an address unit is the smallest
collection of bits that can be addressed. In other words, an address unit is the number of bits spanned by
the addresses addr and addr+1. The most prevalent machines use 8-bit address units, but other address unit
sizes exist.
In this standard, the size of a cell is an implementation-defined number of address units. Forth implemented
on a 16-bit microprocessor could use a 16-bit cell and an implementation on a 32-bit machine could use
a 32-bit cell. Less common cell sizes (e.g., 18-bit or 36-bit machines, etc.) could implement Forth sys-
tems with their native cell sizes. In all of these systems, Forth words such as DUP and ! do the same
things (duplicate the top cell on the stack and store the second cell into the address given by the first cell,
respectively).
Similarly, the definition of a character has been generalized to be an implementation-defined number of
address units (but at least eight bits). This removes the need for a Forth implementor to provide 8-bit
characters on processors where it is inappropriate. For example, on an 18-bit machine with a 9-bit address
244
Forth 2012 D. Portability guide
unit, a 9-bit character would be most convenient. Since, by definition, you can’t address anything smaller
than an address unit, a character must be at least as big as an address unit. This will result in big characters
on machines with large address units. An example is a 16-bit cell addressed machine where a 16-bit
character makes the most sense.
245
D. Portability guide Forth 2012
246
Forth 2012 D. Portability guide
To convert a single-cell number to a double-cell number, Forth 94 provided the operator S>D. To convert
a double-cell number to single-cell, Forth programmers have traditionally used DROP. However, this trick
doesn’t work on sign-magnitude machines. For portability a D>S operator is available. Converting an
unsigned single-cell number to a double-cell number can be done portably by pushing a zero on the stack.
D.4.1 Definitions
Traditionally, Forth definitions have consisted of the name of the Forth word, a dictionary search link, data
describing how to execute the definition, and parameters describing the definition itself. These components
have historically been referred to as the name, link, code, and parameter fields. No method for accessing
these fields has been found that works across all of the Forth implementations currently in use. Therefore,
a portable Forth program may not use the name, link, or code field in any way. Use of the parameter field
(renamed to data field for clarity) is limited to the operations described below.
Only words defined with CREATE or with other defining words that call CREATE have data fields. The
other defining words in the standard (VARIABLE, CONSTANT, :, etc.) might not be implemented with
CREATE. Consequently, a Standard Program must assume that words defined by VARIABLE, CONSTANT,
:, etc., may have no data fields. There is no portable way for a Standard Program to modify the value of a
constant or to “patch” a colon definition at run time. The DOES> part of a defining word operates on a data
field, so DOES> may only be used on words ultimately defined by CREATE.
In standard Forth, FIND, [’] and ’ (tick) return an unspecified entity called an execution token. There
are only a few things that may be done with an execution token. The token may be passed to EXECUTE
to execute the word ticked or compiled into the current definition with COMPILE,. The token can also
be stored in a variable or other data structure and used later. Finally, if the word ticked was defined via
CREATE, >BODY converts the execution token into the word’s data-field address.
An execution token cannot be assumed to be an address and may not be used as one.
D.4.2 Stacks
In some Forth implementations, it is possible to find the address of a stack in memory and manipulate the
stack as an array of cells. This technique is not portable. On some systems, especially Forth-in-hardware
systems, the stacks might be in memory that can’t be addressed by the program or might not be in memory
at all. Forth’s parameter and return stacks must be treated as stacks.
A Standard Program may use the return stack directly only for temporarily storing values. Every value
examined or removed from the return stack using R@, R>, or 2R> must have been put on the stack explicitly
using >R or 2>R. Even this must be done carefully because the system may use the return stack to hold
return addresses and loop-control parameters. Section 3.2.3.3 Return stack of the standard has a list of
restrictions.
247
D. Portability guide Forth 2012
D.5 Summary
The Forth Standard does not force anyone to write a portable program. In situations where performance
is paramount, the programmer is encouraged to use every trick available. On the other hand, if portability
to a wide variety of systems is needed(or anticipated), this standard provides the tools to accomplish this.
There might be no such thing as a completely portable program. A programmer, using this guide, should
intelligently weigh the tradeoffs of providing portability to specific machines. For example, machines that
use sign-magnitude numbers are rare and probably don’t deserve much thought. But, systems with different
cell sizes will certainly be encountered and should be provided for. In general, making a program portable
clarifies both the programmer’s thinking process and the final program.
248
Forth 2012 E. Alphabetic list of words
Annex E
(informative)
Alphabetic list of words
In the following list, the last, four-digit, part of the reference number establishes a sequence corresponding
to the alphabetic ordering of all standard words. The first two or three parts indicate the word set and
glossary section in which the word is defined.
249
E. Alphabetic list of words Forth 2012
250
Forth 2012 E. Alphabetic list of words
251
E. Alphabetic list of words Forth 2012
252
Forth 2012 E. Alphabetic list of words
253
E. Alphabetic list of words Forth 2012
254
Forth 2012 E. Alphabetic list of words
255
E. Alphabetic list of words Forth 2012
256
Forth 2012 E. Alphabetic list of words
257
E. Alphabetic list of words Forth 2012
258