Wil Baden 1998-08-26
With Forth Programmer's Handbook, ISBN 0-9662156-0-5, as the only current general book about Forth, for portability today's Forth implementations and tutorials should agree with it.
Here are words that are in FPH but not in Standard Forth.
.' 2+ 2- C+! CONTEXT CURRENT CVARIABLE DASM DEFER EMPTY INCLUDE IS L LOCATE M- M/ NOT T* T/ VOCABULARY WH WHERE [DEFINED] [UNDEFINED]These words are described as common usage. Some of them are implementation dependent. Others have simple definitions in Standard Forth. Potential definitions for those which can be defined in Standard Forth are given here for systems that are missing them.
Existing definitions are surely superior, especially when implementation dependent.
Comment out definitions that you already have or are improving.
Definitions in Standard Forth by Wil Baden. Any similarity with anyone else's code is coincidental, historical, or inevitable.
TEXTNOT
( x -- flag )
0=
, used for program clarity to reverse the
result of a previous test.
[DEFINED]
( "name" -- flag )
[UNDEFINED]
( "name" -- flag )
C+!
( n addr -- )
: NOT ( n -- flag ) S" 0= " EVALUATE ; IMMEDIATE : [DEFINED] ( "name" -- flag ) BL WORD FIND NIP 0<> ; IMMEDIATE : [UNDEFINED] ( "name" -- flag ) BL WORD FIND NIP 0= ; IMMEDIATE : C+! ( n addr -- ) DUP >R C@ + R> C! ;
2+
( n -- n+2 )
2-
( n -- n-2 )
INCLUDE
( "filename" -- )
DEFER
( "name" -- )
IS
( xt "name" -- )
DEFER
.
: 2+ ( n -- n+2 ) 2 + ; : 2- ( n -- n-2 ) 2 - ; : INCLUDE ( "filename" -- ) BL WORD COUNT INCLUDED DECIMAL ; : Uninitialized-DEFER ( -- ) TRUE ABORT" Uninitialized DEFER." ; : DEFER CREATE ( "name" -- ) ['] Uninitialized-DEFER , DOES> @ EXECUTE ; : IS ( xt "name" -- ) ' ( xt xt2) STATE @ IF POSTPONE LITERAL POSTPONE >BODY POSTPONE ! ELSE >BODY ! THEN ; IMMEDIATE
M-
( d . n -- d . )
M/
( d . n -- q )
T*
( d . n -- t . . )
T/
( t . . u -- d . )
M*/
( d . n u -- d . )
: M- ( d . n -- d . ) NEGATE M+ ; : M/ ( d . n -- q ) SM/REM NIP ; : TNEGATE ( t . . -- -t . . ) >R 2DUP OR DUP IF DROP DNEGATE 1 THEN R> + NEGATE ; : T* ( d . n -- t . . ) ( d0 d1 n) 2DUP XOR >R ( R: sign) >R DABS R> ABS 2>R ( d0)( R: sign d1 n) R@ UM* 0 ( t0 d1 0) 2R> UM* ( t0 d1 0 d1*n .)( R: sign) D+ ( t0 t1 t2) R> 0< IF TNEGATE THEN ; : T/ ( t . . u -- d . ) ( t0 t1 t2 u) OVER >R >R ( t0 t1 t2)( R: t2 u) DUP 0< IF TNEGATE THEN R@ UM/MOD ( t0 rem d1) ROT ROT ( d1 t0 rem) R> UM/MOD ( d1 rem' d0)( R: t2) NIP SWAP ( d0 d1) R> 0< IF DNEGATE THEN ; : M*/ ( d . n u -- d . ) >R T* R> T/ ;
VOCABULARY
( "name" -- )
\ From Standard Forth Rationale A.16.6.2.0715. : DO-VOCABULARY ( -- ) DOES> @ >R ( )( R: widnew) GET-ORDER SWAP DROP ( wid_n ... wid_2 n) R> SWAP SET-ORDER ; : VOCABULARY ( "name" -- ) WORDLIST CREATE , DO-VOCABULARY ;
EMPTY
( -- )
EMPTY
, the
default word list for both CONTEXT
and CURRENT
is
FORTH
." FPH 2nd edn, p. 169
POSSIBLY
( "name" -- )
ANEW
.
ANEW
( "name" -- )
ANEW name
. If the
word name already exists, it and all subsequent words
are forgotten from the current dictionary, then a MARKER
word name is created that does nothing. This is usually
placed at the start of a file. When the code is reloaded,
any prior version is automatically pruned from the
dictionary.
MARKER
word.
EMPTY
.
: POSSIBLY ( "name" -- ) BL WORD FIND ?DUP AND IF EXECUTE THEN ; : ANEW ( "name" -- ) >IN @ POSSIBLY >IN ! MARKER ; : EMPTY ( -- ) S" ANEW --- DECIMAL " EVALUATE ;
.'
( addr -- )
CONTEXT
( -- a-addr )
CURRENT
( -- a-addr )
CVARIABLE
( "name" -- )
DASM
( addr -- )
L
( -- )
LOCATE
( "name" -- )
VIEW
name performs
a similar function. Implementation dependent.
WH
( "name" -- )
WHERE
, defined for typing convenience.
Implementation dependent.
WHERE
( "name" -- )
These are implementation dependent, and can't have Standard definitions.