You can list all the installed words in froth
with the
WORDS
word, or use froth.dictionary()
from R.
The following is all the words referenced in the previous chapters.
-
<NUMBER> ( -- n )
: pushes a number onto the stack -
emit ( n -- )
: prints the top number of the stack, interpreting as ASCII -
cr ( -- )
: prints a new line -
." xxx" ( -- )
: printsxxx
on the terminal. Note that"
terminates the string. -
: xxx yyy ; ( -- )
: defines a wordxxx
comprised of wordsyyy
-
FORGET xxx ( -- )
: removes the current wordxxx
. Ifxxx
had a previous definition it reverts to that previous value, and otherwise the word is removed. -
+ (a b -- n)
: addsa+b
-
* (a b -- n)
: multipliesa*b
-
. (n -- )
: pops the top element of stack and prints it -
clear ( x1 x2 ... -- )
: removes all elements of the stack -
reset ( -- )
: resetfroth
to defaults (wipe all user definitions, reinitialize all built-in definitions, reset all stacks) -
/ ( a b -- n )
: division (5 2 / => 2.5
) -
%/% ( a b -- n)
: integer division (5 2 %/% => 2
) -
mod ( a b -- rem )
: remainder when dividinga / b
-
/mod ( a b -- rem quot )
: integer dividesa %/% b
, pushes the remainder and then the quotient -
^ ( a b -- n )
: raisesa^b
-
negate ( a -- n )
: negatesa
-
abs ( a -- n )
: takes the absolute value ofa
-
min ( a b -- min )
: pushesmin(a,b)
-
max ( a b -- max )
: pushesmax(a,b)
-
sqrt ( a -- root )
: pushessqrt(a)
-
SWAP ( a b -- b a )
: swap top two stack elements -
DUP ( n -- n n )
: duplicate the top stack element -
OVER ( a b -- a b a )
: duplicate the second element to the top of the stack -
ROT ( a b c -- b c a )
: rotate the third item to the top -
DROP ( n -- )
: discard the top element of the stack -
.S ( -- )
: print out the contents of the stack -
2SWAP ( a b c d -- c d a b )
: swap the top two pairs -
2DUP ( a b -- a b a b )
: duplicate the top pair -
2OVER ( p1 p2 -- p1 p2 p1 )
: duplicate the second pair (p1
) to the top -
2DROP ( a b -- )
: discard the top pair -
>R ( n -- )
: moves the value on the parameter stack to the return stack -
R> ( -- n )
: moves the value on the return stack to the parameter stack -
R@ ( -- n )
: copies the value on the return stack to the parameter stack -
1+ ( n1 -- n2 )
: adds 1 -
1- ( n1 -- n2 )
: subtracts 1 -
2+ ( n1 -- n2 )
: adds 2 -
2- ( n1 -- n2 )
: subtracts 2 -
2* ( n1 -- n2 )
: multiplies by 2 -
2/ ( n1 -- n2 )
: divides by 2 -
*/ ( a b c -- n )
: pushes(a*b) / c
-
*/mod ( a b c -- rem quot )
: pushes the remainder and quotient of(a*b) %/% c
-
if
: if top of stack isTRUE
, executes. Else jumps to the nextelse
orthen
block. -
else
: executes commands untilthen
only if the precedingif
did not execute. -
then
: terminates anif
orif...else
block. -
\
: signals to the interpreter that you’re making a newline without running commands -
=
: are the top two elements equal? -
<
: is the top element greater than the first? -
>
: is the top element less than the first? -
<>
: are the top two elements not equal? -
0=
: is the top element zero? -
0<
: is the top element greater than zero? -
0>
: is the top element less than zero? -
<=
: is top element greater than or equal to the second? -
>=
: is top element less than or equal to the second? -
AND
: pushTRUE
if the top two elements are bothTRUE
-
OR
: pushTRUE
if at least one of the top two elements areTRUE
-
XOR
: pushTRUE
if exactly one of the top two elements isTRUE
-
NOT
: pushTRUE
if the top element isFALSE
and vice-versa -
?DUP
: duplicate top value if it is nonzero -
ABORT"
: abort if top value true, print error message (terminated by"
) -
DO ( end start -- )
: starts a definite loop fromstart
toend
-
LOOP ( -- )
: increments the loop counter by 1 -
+LOOP ( n -- )
: increments the loop counter by n -
I ( -- n )
: copies the current loop counter to the stack -
J ( -- n )
: copies the enclosing loop’s counter to the stack -
K ( -- n )
: copies the enclosing loop’s enclosing loop’s counter to the stack -
BEGIN ( -- )
: starts an indefinite loop -
AGAIN ( -- )
: returns toBEGIN
-
WHILE ( flag -- )
: ifflag
, continue; else jump to afterREPEAT
-
REPEAT ( -- )
: returns toBEGIN
followingWHILE
-
LEAVE ( -- )
: leave the current loop immediately -
VARIABLE xxx
: creates a variable namedxxx
-
! ( n addr -- )
: stores the valuen
at addressaddr
-
@ ( addr -- n )
: copies the value ataddr
to the stack -
? ( addr -- )
: prints the value ofaddr
-
+! ( n addr -- )
: adds the valuen
to the value ataddr
-
CONSTANT xxx (n -- )
: creates a constant calledxxx
that storesn
;xxx
returnsn
when called -
ALLOT ( addr ncells -- )
: allocatesncells
cells ataddr
-
CREATE xxx y1 , y2 , ... yn ,
: creates an arrayxxx
with valuesy1, y2, ... yn
-
CELLS ( n -- )
: creates a memory address offset for arrays -
FILL ( addr ncells val -- )
: fillsncells
cells of memory beginning ataddr
withval
-
ERASE ( addr ncells -- )
: fillsncells
cells of memory beginning ataddr
with 0 -
REALLOT ( addr ncells -- )
: reallots array ataddr
to have sizencells
. -
EXTEND ( addr ncells -- )
: extends the array ataddr
byncells
cells -
LENGTH ( addr -- len )
: pushes the length of the array ataddr
onto the stack -
LENGTH? ( addr -- )
: prints the length of the array ataddr
-
' xxx ( -- addr )
: attempts to findxxx
in the dictionary, and pushes an execution token forxxx
to the stack if found -
EXECUTE ( xt -- )
: executes an execution token on top of the stack -
['] xxx ( -- addr )
: currently equivalent to'
forfroth