Nothing
knitr::opts_chunk$set(echo = TRUE) library(froth, quietly = TRUE)
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 stackemit ( n -- )
: prints the top number of the stack, interpreting as ASCIIcr ( -- )
: prints a new line." xxx" ( -- )
: prints xxx
on the terminal. Note that "
terminates the string.: xxx yyy ; ( -- )
: defines a word xxx
comprised of words yyy
FORGET xxx ( -- )
: removes the current word xxx
. If xxx
had a previous definition it reverts to that previous value, and otherwise the word is removed.+ (a b -- n)
: adds a+b
* (a b -- n)
: multiplies a*b
. (n -- )
: pops the top element of stack and prints itclear ( x1 x2 ... -- )
: removes all elements of the stackreset ( -- )
: reset froth
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 dividing a / b
/mod ( a b -- rem quot )
: integer divides a %/% b
, pushes the remainder and then the quotient^ ( a b -- n )
: raises a^b
negate ( a -- n )
: negates a
abs ( a -- n )
: takes the absolute value of a
min ( a b -- min )
: pushes min(a,b)
max ( a b -- max )
: pushes max(a,b)
sqrt ( a -- root )
: pushes sqrt(a)
SWAP ( a b -- b a )
: swap top two stack elementsDUP ( n -- n n )
: duplicate the top stack elementOVER ( a b -- a b a )
: duplicate the second element to the top of the stackROT ( a b c -- b c a )
: rotate the third item to the topDROP ( n -- )
: discard the top element of the stack.S ( -- )
: print out the contents of the stack2SWAP ( a b c d -- c d a b )
: swap the top two pairs2DUP ( a b -- a b a b )
: duplicate the top pair2OVER ( p1 p2 -- p1 p2 p1 )
: duplicate the second pair (p1
) to the top2DROP ( a b -- )
: discard the top pair>R ( n -- )
: moves the value on the parameter stack to the return stackR> ( -- n )
: moves the value on the return stack to the parameter stackR@ ( -- n )
: copies the value on the return stack to the parameter stack1+ ( n1 -- n2 )
: adds 11- ( n1 -- n2 )
: subtracts 12+ ( n1 -- n2 )
: adds 22- ( n1 -- n2 )
: subtracts 22* ( n1 -- n2 )
: multiplies by 22/ ( 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 is TRUE
, executes. Else jumps to the next else
or then
block.else
: executes commands until then
only if the preceding if
did not execute.then
: terminates an if
or if...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
: push TRUE
if the top two elements are both TRUE
OR
: push TRUE
if at least one of the top two elements are TRUE
XOR
: push TRUE
if exactly one of the top two elements is TRUE
NOT
: push TRUE
if the top element is FALSE
and vice-versa?DUP
: duplicate top value if it is nonzeroABORT"
: abort if top value true, print error message (terminated by "
)DO ( end start -- )
: starts a definite loop from start
to end
LOOP ( -- )
: increments the loop counter by 1+LOOP ( n -- )
: increments the loop counter by nI ( -- n )
: copies the current loop counter to the stackJ ( -- n )
: copies the enclosing loop's counter to the stackK ( -- n )
: copies the enclosing loop's enclosing loop's counter to the stackBEGIN ( -- )
: starts an indefinite loopAGAIN ( -- )
: returns to BEGIN
WHILE ( flag -- )
: if flag
, continue; else jump to after REPEAT
REPEAT ( -- )
: returns to BEGIN
following WHILE
LEAVE ( -- )
: leave the current loop immediatelyVARIABLE xxx
: creates a variable named xxx
! ( n addr -- )
: stores the value n
at address addr
@ ( addr -- n )
: copies the value at addr
to the stack? ( addr -- )
: prints the value of addr
+! ( n addr -- )
: adds the value n
to the value at addr
CONSTANT xxx (n -- )
: creates a constant called xxx
that stores n
; xxx
returns n
when calledALLOT ( addr ncells -- )
: allocates ncells
cells at addr
CREATE xxx y1 , y2 , ... yn ,
: creates an array xxx
with values y1, y2, ... yn
CELLS ( n -- )
: creates a memory address offset for arraysFILL ( addr ncells val -- )
: fills ncells
cells of memory beginning at addr
with val
ERASE ( addr ncells -- )
: fills ncells
cells of memory beginning at addr
with 0REALLOT ( addr ncells -- )
: reallots array at addr
to have size ncells
.EXTEND ( addr ncells -- )
: extends the array at addr
by ncells
cellsLENGTH ( addr -- len )
: pushes the length of the array at addr
onto the stackLENGTH? ( addr -- )
: prints the length of the array at addr
' xxx ( -- addr )
: attempts to find xxx
in the dictionary, and pushes an execution token for xxx
to the stack if foundEXECUTE ( xt -- )
: executes an execution token on top of the stack['] xxx ( -- addr )
: currently equivalent to '
for froth
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.