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
information 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.