music |

| | # OSdata.com |

# reference manual

## summary

The reference manual for the milo programming environment.

**The most recent version of my self-contained development environment is at stable release version or http://www.twiddledom.com/coder/js78.html**

Free Open Souce: Licensed under MIT license. License printed in full below.

# reference manual

## summary

# reference manual:

The working software is available at http://www.osdata.com/milo.html.

## overview:

This is the reference guide to this software. Use this section to look up information. Use the instructions area for to learn how to program computers.

The initial version of this software combines Turtle Graphics, Forth, and PostScript. While there is nice overlap between these technologies, there are also some incompatibilities.

A control for language parsing mode is planned, allowing a programmer to specify that coding is occuring in a particular programming language. Otherwise, a generic general combined language (documented below) is in use.

**Stack** The stack uses a PostScript approach of storing objects rather than low level characters and fixed-width binary numbers. A mode control is planned to allow a F Forth-style stack. Most Forth words should work fine without any knowledge of the stack storing objects. Some Forth words (such as byte or double integer words) may work as expected, with automatic translation between stack styles.

**Input** The input area is initially labelled “Type commands here.” There is a separate enter button to allow multi-line input (JavaScript does not distinguish between the return key and the enter key, so all uses of either key are to add a CR/LF to the input text. Further testing is needed, but the input area seems to accept input of any printable characters in the UTF-16 character set [unconfirmed]. Further testing is needed to filter out all of the extra garbage each web browser automatically adds to the user’s input text.

**Output** The output area is immediately above the input area. This is where output text is normally directed. There will be text drawing commands for the canvas area.

**Canvas** The canvas area is near the top of the web page. This is the area for visual output. There is currently a problem interpretting mouse location if the web page is scrolled any amount from the top of the page. This is on the to-do list.

**Words** The interpreter parses in a manner very similar to both Forth and PostScript, dividing input into tokens, looking up those tokens in a dictionary, with a fallback of number processing (placing found numbers on the stack).

## parsing notes:

The first goal is to accept every valid program in the supported programming languages and correctly implement the code specified by the valid program.

The second goal is to try to be very forgiving of errors. Although most compilers try to reject all invalid programs, this is *not* an important goal for this project. This project will attempt to take the approach commonly used in web browsers of trying to be very forgiving of errors.

## drawing:

There are direct graphic-user interface access to some drawing capabilities. Some of these capabilities are not yet implemented as words.

The GrafX button reveals buttons for controlling the turtle. All of the turtle buttons are available as words. Beneath the turtle buttons are radio buttons for grafx, rectangle, and circle.

If the user clicks the mouse anywhere in the canvas, one of the three drawing operations will occur.

In grafx mode, the mouse click moves the turtle position, without drawing.

In rectangle mode, the mouse click chooses one corner of the rectangle and further motion of the mouse with the button held down will choose the far diagonal corner of the rectangle.

In circle mode, the mouse click chooses the center of the circle and further motion of the mouse with the button held down will choose the radius of the circle.

After drawing each rectangle or circle, two additional buttons will appear.

The move radio button will cause mouse clicks (and moves with the button down) to move the most recently drawn circle or rectangle. Clicking on the rectangle or circle radio buttons will return to drawing mode.

The delete button will remove the last item drawn (circle, rectangle, or turtle line). Each subsequent use of the delete button will remove one more item drawn in reverse order that they were drawn.

The drawing button will reveal a number of controls for the turtle, rectangles, circles, and lines. Not all of these capabilities have been implemented as word yet.

The line, arc, and cloud buttons are not fully functional yet.

## words:

Words are arranged in alphabetical order based on the UTF-16 collating sequence. Tables for logical grouping of words will be added.

Character case does not matter (except in character strings). All tokens are converted into capital letters upon input.

word | name | language category |

stack start --- stack end |

description |

| **white space** |

The following white space characters are used as separators between tokens (unless part of a string): HT (horizontal tab), LF (line feed), VT (vertical tab), FF (form feed), CR (carriage return), and space. **Implementation note:** not all of these are currently surviving to the interpreter. The space is recommended as the primary white space character. |

! | **store** (exclamation point) |

x a-addr --- |

Pops the top two items from the stack and stores the second object down from the stack (x) into the memory cell designated by the number that was on top of the stack (a-addr). All cells are numbered consecutively, starting at zero. Each cell holds an object. The word **here** gives the expected next free memory cell. Current implementation allows ignoring here and storing at any arbitrary random-access memory cell, although this use might lead to serious conflicts with the use of the here word. The maximum number of memory cells is implementation-defined (limited by the actual web browser used). Checks to confirm that there are at least two objects on the stack and that the object on the top of the stack is numeric (either a binary number or a string that can be converted to a number). Stops and reports any error. |

' | **tick** (single quote) |

<spaces>name --- xt |

This word is not in its final form -- this is a temporary transition word until several other related words are implemented. The object on the top of the stack is (case-insensitive) match checked against the dictionary. If a matching character string (name) is found in the dictionary, the compliation address (xt) is pushed to the top of the stack. |

* | **multiply** (asterisk) |

n1|u1 n2|u2 --- n3|u3 |

Pops the top two items on the stack and multiplies the top number (n2 or u2) by the second to top number (n1 or u1), then pushes the total (n3 or u3) to the top of the stack. **Implementation note:** This word will accept both integer and floating point input and will produce floating point output whenever there is a non-integer result. Checks to confirm that both of the top two objects on the stack are numbers (either as binary numbers or as character strings that convert to numbers). Stops without action (other than error report) if either test fails or if there are less than two objects on the stack. |

+ | **add** (plus) |

n1|u1 n2|u2 --- n3|u3 |

Pops the top two items on the stack and adds the top number (n2 or u2) to the second to top number (n1 or u1), then pushes the total (n3 or u3) to the top of the stack. Checks to confirm that both of the top two objects on the stack are numbers (either as binary numbers or as character strings that convert to numbers) or if there are less than two objects on the stack. Stops without action (other than error report) if either test fails. **Implementation note:** This word will accept both integer and floating point input and will produce floating point output whenever there is a non-integer result. |

+! | **plus store** (plus-store) |

n1|u1 a-addr --- |

Pops the top two items on the stack. The item on the top of the stack (a-addr) is a numeric address into random-access memory. The item that is second on the stack (n1 or u1) is a number to be added to the object stored in the designated memory cell. A check is made to guarantee that the object in memory is a number (either as a binary number or a character string that can be converted into a valid number). If this check fails, the word stops with an error report, but does not restore the previous state of the stack, although the object in memory is unchanged. Checks to confirm that both of the top two objects on the stack are numbers (either as binary numbers or as character strings that convert to numbers) or if there are less than two objects on the stack. Stops without action (other than error report) if either test fails. |

- | **subtract** or **minus** (hyphen) |

n1|u1 n2|u2 --- n3|u3 |

Pops the top two items on the stack and subtracts them, then pushes the total (n3 or u3) to the top of the stack. The number on the top of the stack (n2 or u2) is subtracted from the number second on the stack (n1 or u1). **Example:** algebriac notation **3 - 2 =** would be converted into RPN (stack) notation **3 2 - .** (answer is 1). Checks to confirm that both of the top two objects on the stack are numbers (either as binary numbers or as character strings that convert to numbers). Stops without action (other than error report) if either test fails or if there are less than two objects on the stack. **Implementation note:** This word will accept both integer and floating point input and will produce floating point output whenever there is a non-integer result. |

. | **dot** (period, dot) |

n --- |

Pops the top object from the stack (n) and places it into the output text area. If the stack is empty, this word instead generates a stack empty error report. |

.S | dot-s | Forth non-standard I/O |

Shows all of the objects on the stack (in order from bottom to top) without disturbing the stack. |

? | **fetch and display** (question mark) | Forth nonstandard I/O |

a-addr --- |

Checks to make sure that there is at least one object on the stack and that the object on the top of the stack is numeric (either as a binary number or as a character string that can be converted into a valid number). Stops and reports on error. Pops the object from the top of the stack (a-addr) and finds the object in the memory cell with that number. Outputs the object found in that memory cell to the output text area. This is equivalent to using the two words @ . |

@ | **fetch** (at sign) |

a-addr --- x |

Checks to make sure that there is at least one object on the stack and that the object on the top of the stack is numeric (either as a binary number or as a character string that can be converted into a valid number). Stops and reports on error. Pops the object from the top of the stack (a-addr) and finds the object (x) in the memory cell with that number. Pushes the object found in memory (x) on to the top of the stack. |

/ | **divide** (slash) |

n1 n2 --- n3 |

Pops the top two items on the stack and divides them, then pushes the total (n3) to the top of the stack. The number on the top of the stack (n2) is divided from the number second on the stack (n1). **Example:** algebriac notation **4/2 =** would be converted into RPN (stack) notation **4 2 / .** (answer is 2). Checks to confirm that both of the top two objects on the stack are numbers (either as binary numbers or as character strings that convert to numbers). Stops without action (other than error report) if either test fails or if there are less than two objects on the stack. **Implementation note:** This word will accept both integer and floating point input and will produce floating point output whenever there is a non-integer result. Use the special word **idiv** to obtain a Forth-style integer-only result. |

1+ | one plus (increment) |

n1 --- n2 |

Pops the number from the top of the stack (n1), adds one (1), and places the sum (n2) on the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

1- | one minus (decrement) |

n1 --- n2 |

Pops the number from the top of the stack (n1), subtracts one (1), and places the sum (n2) on the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

10* | ten times (ten star, ten asterisk) | Forth uncontrolled mathematics |

n1|u1 --- n2 |

Pops the top item from the stack (n1 or u1), multiplies by ten (10), then pushes the product (n2) to the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

10+ | ten plus | Forth nonstandard mathematics |

n1 --- n2 |

Pops the number from the top of the stack (n1), adds ten (10), and places the sum (n2) on the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

10- | ten minus | Forth nonstandard mathematics |

n1|u1 --- n2 |

Pops the top item from the stack (n1 or u1), subtracts ten (10), then pushes the difference (n2) to the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

10/ | ten divide (ten slash) | Forth nonstandard mathematics |

n1|u1 --- n2 |

Pops the top item from the stack (n1 or u1), divides by ten (10), then pushes the quotient (n2) to the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

16* | 16 times (16 star, 16 asterisk) | Forth uncontrolled mathematics |

n1|u1 --- n2 |

Pops the top item from the stack (n1 or u1), multiplies by 16, then pushes the product (n2) to the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

16+ | 16 plus | Forth nonstandard mathematics |

n1 --- n2 |

Pops the number from the top of the stack (n1), adds 16, and places the sum (n2) on the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

16- | 16 minus | Forth nonstandard mathematics |

n1|u1 --- n2 |

Pops the top item from the stack (n1 or u1), subtracts 16, then pushes the difference (n2) to the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

16/ | 16 divide (16 slash) | Forth nonstandard mathematics |

n1|u1 --- n2 |

Pops the top item from the stack (n1 or u1), divides by 16, then pushes the quotient (n2) to the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

2* | two times (two star, two asterisk) |

n1|u1 --- n2 |

Pops the number from the top of the stack (n1), multiplies by two (2), and places the product (n2) on the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

2+ | two plus | Forth nonstandard mathematics |

n1 --- n2 |

Pops the number from the top of the stack (n1), adds two (2), and places the sum (n2) on the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

2- | two minus | Forth nonstandard mathematics |

n1|u1 --- n2 |

Pops the top item from the stack (n1 or u1), subtracts two (2), then pushes the difference (n2) to the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

2/ | two slash |

n1 --- n2 |

Pops the number from the top of the stack (n1), divides by two (2), and places the quotient (n2) on the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

3+ | three plus | Forth nonstandard mathematics |

n1 --- n2 |

Pops the number from the top of the stack (n1), adds three (3), and places the sum (n2) on the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

3- | three minus | Forth nonstandard mathematics |

n1|u1 --- n2 |

Pops the top item from the stack (n1 or u1), subtracts three (3), then pushes the difference (n2) to the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

4* | four times (four star, four asterisk) | Forth uncontrolled mathematics |

n1|u1 --- n2 |

Pops the top item on the stack(n1 or u1), multiplies by four (4), then pushes the product (n2) to the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

4+ | four plus | Forth nonstandard mathematics |

n1 --- n2 |

Pops the number from the top of the stack (n1), adds four (4), and places the sum (n2) on the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

4- | four minus) | Forth nonstandard mathematics |

n1|u1 --- n2 |

Pops the top item from the stack (n1 or u1), subtracts four (4), then pushes the difference (n2) to the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

4/ | four divide (four slash) | Forth nonstandard mathematics |

n1|u1 --- n2 |

Pops the top item from the stack (n1 or u1), divides by four (4), then pushes the quotient (n2) to the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

5+ | five plus | Forth nonstandard mathematics |

n1 --- n2 |

Pops the number from the top of the stack (n1), adds five (5), and places the sum (n2) on the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

5- | five minus | Forth nonstandard mathematics |

n1|u1 --- n2 |

Pops the top item from the stack (n1 or u1), subtracts five (5), then pushes the difference (n2) to the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

6+ | six plus | Forth nonstandard mathematics |

n1 --- n2 |

Pops the number from the top of the stack (n1), adds six (6), and places the sum (n2) on the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

6- | six minus | Forth nonstandard mathematics |

n1|u1 --- n2 |

Pops the top item from the stack (n1 or u1), subtracts six (6), then pushes the difference (n2) to the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

7+ | seven plus | Forth nonstandard mathematics |

n1 --- n2 |

Pops the number from the top of the stack (n1), adds seven (7), and places the sum (n2) on the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

7- | seven minus | Forth nonstandard mathematics |

n1|u1 --- n2 |

Pops the top item from the stack (n1 or u1), subtracts seven (7), then pushes the difference (n2) to the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

8* | eight times (eight star, eight asterisk) | Forth uncontrolled mathematics |

n1|u1 --- n2 |

Pops the top item from the stack (n1 or u1), multiplies by eight (8), then pushes the product (n2) to the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

8+ | eight plus | Forth nonstandard mathematics |

n1 --- n2 |

Pops the number from the top of the stack (n1), adds eight (8), and places the sum (n2) on the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

8- | eight minus | Forth nonstandard mathematics |

n1|u1 --- n2 |

Pops the top item from the stack (n1 or u1), subtracts eight (8), then pushes the difference (n2) to the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

8/ | eight divide (eight slash) | Forth nonstandard mathematics |

n1|u1 --- n2 |

Pops the top item from the stack (n1 or u1), divides by eight (8), then pushes the quotient (n2) to the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

9+ | nine plus | Forth nonstandard mathematics |

n1 --- n2 |

Pops the number from the top of the stack (n1), adds nine (9), and places the sum (n2) on the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

9- | nine minus | Forth nonstandard mathematics |

n1|u1 --- n2 |

Pops the top item from the stack (n1 or u1), subtracts nine (9), then pushes the difference (n2) to the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

abs | abs or absolute value |

n --- u |

Pops the top object from the stack (n), then pushes the absolute value (u) to the top of the stack. Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

add | addition |

num_{1} num_{2} --- sum |

Pops the top two items on the stack and adds the top number (num_{2}) to the second to top number (num_{1}), then pushes the total (sum) to the top of the stack. Checks to confirm that both of the top two objects on the stack are numbers (either as binary numbers or as character strings that convert to numbers) or if there are less than two objects on the stack. Stops without action (other than error report) if either test fails. |

back | back or backwards |

color steplength strokewidth --- |

Moves the turtle backwards one step. If the pen is down, a line is drawn. If the turtle is in show mode, then the turtle is shown. The order of objects expected on the top of the stack are: color, steplength, and strokewidth. |

clear | clear stack |

<any> --- <empty> |

Removes everything from the stack. |

clearcanvas | clear canvas |

--- |

Clears the canvas to the current background color. |

clearstack | clear stack | Forth nonstandard stack |

<any> --- <empty> |

Removes everything from the stack. |

degreestoradians | degrees to radians conversion |

n1|u1 --- n2 |

Checks to make sure there is at least one object on the stack and that the object on the top of the stack is numeric (either binary number or a character string that can be converted into a number). Stops without action (other than error report) if either test fails. If the object on the top of the stack is a valid number (n1 or u1), converts the number (n1 or u1) from degrees to radians and pushes this answer (n2) to the top of the stack. |

depth | depth |

--- +n |

Counts the number of objects on the stack and pushes that number (+n) onto the top of the stack. If there were no objects on the stack, this word pushes 0 (zero) to the top of the stack. |

div | divide or division |

num_{1} num_{2} --- quotient |

Pops the top two items on the stack and divides them, then pushes the total (quotient) to the top of the stack. The number on the top of the stack (num_{2}) is divided from the number second on the stack (num_{1}). **Example:** algebriac notation **4/2 =** would be converted into RPN (stack) notation **4 2 div .** (answer is 2). Checks to confirm that both of the top two objects on the stack are numbers (either as binary numbers or as character strings that convert to numbers). Stops without action (other than error report) if either test fails or if there are less than two objects on the stack. Use the word **idiv** to obtain an integer-only result. |

drawcircle | draw circle |

fillcolor xcenter ycenter radius gradientstartcolor gradientendcolor linecolor strokewidth filltype --- |

Draws a circle in the canvas. The order of items on the stack are: fillcolor, xcenter, ycenter, radius, gradientstartcolor, gradientendcolor, linecolor, strokewidth, filltype. |

drawrectangle | draw rectangle |

linecolor fillcolor itemleft itemtop itemwidth itemheight strokewidth --- |

Draws a rectangle in the canvas. The order of items on the stack are: linecolor, fillcolor, itemleft, itemtop, itemwidth, itemheight, strokewidth. |

drop | drop |

x --- |

Removes the top object (x) on the stack from the stack, leaving the rest of the stack undisturbed. Reports an error if there are no objects on the stack. |

dup | duplicate |

x --- x x |

Duplicates the oject on the top of the stack (x). That is, makes a copy of the object on the top of the stack (not a deep copy for composite objects) and pushes the new copy on to the top of the stack without disturbing the previous object. Reports an error if there are no objects on the stack. |

e | Euler’s number |

--- n |

Places Euler’s number (n) on the top of the stack (approximately 2.718). |

eq | **equal** (equality test) |

any_{1} any_{2} --- bool |

Pops and compares the two top objects on the stack. If the second object on the stack (any_{1}) is equal to the object on top of the stack (any_{2}), pushes Boolean true (bool) to the stack. Otherwise pushes Boolean false (bool) to the stack. Checks to guarantee there are at least two objects on the stack and stops if the test fails. **Implementation note:** Currently only works for binary numbers (integer and floating point numbers of same value are considered equal). |

exch | exchange |

any_{1} any_{2} --- any_{2} any_{1} |

Exchanges the top two objects (any_{1} and any_{2}) on the stack. Checks to guaranatee that there at least two objects on the stack and stops with error if there are only one or zero items on the stack. Same functionality as Forth’s **swap**. |

execute | execute |

xt --- |

Pops the object from the top of the stack (xt). Stops if the item on the top of the stack is not a number or is out of range, but doesn’t yet report any errors. If the number is valid, then runs the word with the designated compilation address (xt). |

forward | forward |

color steplength strokewidth --- |

Moves the turtle forward one step. If the pen is down, a line is drawn. If the turtle is in show mode, then the turtle is shown. The order of objects expected on the top of the stack are: color, steplength, and strokewidth. |

ge | **greater than or eqqual to** (equality test) |

num_{1}|string_{1} num_{2}|string_{2} --- bool |

Pops and compares the two top objects on the stack. If the second object from the top of the stack (num_{1} or string_{1}) is greater than or equal to the object on the top of the stack (num_{2} or string_{2}), pushes Boolean true (bool) to the stack. Otherwise pushes Boolean false (bool) to the stack. Checks to guarantee there are at least two objects on the stack and stops if the test fails. **Implementation note:** Currently only works for binary numbers (integer and floating point numbers of same value are considered equal). |

gt | **greater than** (equality test) |

num_{1}|string_{1} num_{2}|string_{2} --- bool |

Pops and compares the two top objects on the stack. If the second object from the top of the stack (num_{1} or string_{1}) is greater than the object on the top of the stack (num_{2} or string_{2}), pushes Boolean true (bool) to the stack. Otherwise pushes Boolean false (bool) to the stack. Checks to guarantee there are at least two objects on the stack and stops if the test fails. **Implementation note:** Currently only works for binary numbers (integer and floating point numbers of same value are considered equal). |

here | here |

--- addr |

Pushes the numeric address of the next open memory cell location (addr) to the top of the stack. |

hide | hide |

--- |

Hides the turtle. |

home | hide |

--- |

Returns the turtle to the home position (normally the center of the canvas). |

idiv | integer divide |

num_{1} num_{2} --- quotient |

An integer-only divide (we preempted the normal Forth / (divide) word for floating point divides). Pops the top two items on the stack and divides them, then pushes the total (quotient) to the top of the stack. The number on the top of the stack (num_{2}) is divided from the number second on the stack (num_{1}). **Example:** algebriac notation **5/2 =** would be converted into RPN (stack) notation **5 2 idiv .** (answer 2). Checks to confirm that both of the top two objects on the stack are numbers (either as binary numbers or as character strings that convert to numbers) or if there are less than two objects on the stack. Stops without action (other than error report) if either test fails. |

le | **less than or eqqual to** (equality test) |

num_{1}|string_{1} num_{2}|string_{2} --- bool |

Pops and compares the two top objects on the stack. If the second object from the top of the stack (num_{1} or string_{1}) is less than or equal to the object on the top of the stack (num_{2} or string_{2}), pushes Boolean true (bool) to the stack. Otherwise pushes Boolean false (bool) to the stack. Checks to guarantee there are at least two objects on the stack and stops if the test fails. **Implementation note:** Currently only works for binary numbers (integer and floating point numbers of same value are considered equal). |

left | left |

d --- |

Turns the turtle to the left. Expects the number of degrees to turn to the left to be the top item on the stack (d). Modulus 360 applies to the number. Negative numbers reverse the direction of the turn. |

ln2 | natural logarithm of 2 |

--- n |

Places the natural logarithm of 2 (n) on the top of the stack (approximately 0.693). |

ln10 | natural logarithm of 10 |

--- n |

Places the natural logarithm of 10 (n) on the top of the stack (approximately 2.302). |

log2e | base-2 logarithm of E |

--- n |

Places the base-2 logarithm of Euler’s number (n) on the top of the stack (approximately 1.442). |

log10e | base-10 logarithm of E |

--- n |

Places the base-10 logarithm of Euler’s number (n) on the top of the stack (approximately 0.434). |

lt | **less than** (equality test) |

num_{1}|string_{1} num_{2}|string_{2} --- bool |

Pops and compares the two top objects on the stack. If the second object from the top of the stack (num_{1} or string_{1}) is less than the object on the top of the stack (num_{2} or string_{2}), pushes Boolean true (bool) to the stack. Otherwise pushes Boolean false (bool) to the stack. Checks to guarantee there are at least two objects on the stack and stops if the test fails. **Implementation note:** Currently only works for binary numbers (integer and floating point numbers of same value are considered equal). |

max | maximum |

n1|u1 n2|u2 --- n3 |

num_{1} num_{2} --- num_{3} |

Pops the top item from the stack (n1 or u1 or num_{1}) and the second item from the top (n2 or u2 or num_{2}), then pushes the maximum (larger) of the two numbers (n3 or num_{3}) to the top of the stack. Checks to confirm that there is at least two items on the stack and the top two objects on the stack are both numbers (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

min | minimum |

n1|u1 n2|u2 --- n3 |

num_{1} num_{2} --- num_{3} |

Pops the top item from the stack (n1 or u1 or num_{1}) and the second item from the top (n2 or u2 or num_{2}), then pushes the minimum (smaller) of the two numbers (n3 or num_{3}) to the top of the stack. Checks to confirm that there is at least two items on the stack and the top two objects on the stack are both numbers (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

mod | modulus |

n1 n2 --- n3 |

int_{1} int_{2} --- remainder |

Pops the top two items on the stack and determines the modulus, then pushes the result (n3 or remainder) to the top of the stack. The number on the top of the stack (n2 or int_{2}) is mod from the number second on the stack (n1 or int_{1}). **Example:** algebriac notation **5 mod 3 =** would be converted into RPN (stack) notation **5 3 mod .** (the answer to the previous equation is 2) Checks to confirm that both of the top two objects on the stack are numbers (either as binary numbers or as character strings that convert to numbers). Stops without action (other than error report) if either test fails or if there are less than two objects on the stack. |

mul | multiply or multipication |

num_{1} num_{2} --- product |

Pops the top two items on the stack and multiplies the top number (num_{2}) by the second to top number (num_{1}), then pushes the total (product) to the top of the stack. Checks to confirm that both of the top two objects on the stack are numbers (either as binary numbers or as character strings that convert to numbers). Stops without action (other than error report) if either test fails or if there are less than two objects on the stack. |

ne | **not equal** (equality test) |

any_{1} any_{2} --- bool |

Pops and compares the two top objects on the stack. If the second object on the stack (any_{1}) is not equal to the top object on the stack (any_{2}), pushes Boolean true (bool) to the stack. Otherwise pushes Boolean false (bool) to the stack. Checks to guarantee there are at least two objects on the stack and stops if the test fails. **Implementation note:** Currently only works for binary numbers (integer and floating point numbers of same value are considered equal). |

neg | unary negate or unary negation |

num_{1} --- num_{2} |

Negate the number on the top of the stack (num_{1}), giving the arithmetic inverse (num_{2}). Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

negate | unary negate |

n1 --- n2 |

Negate the number on the top of the stack (n1), giving the arithmetic inverse (n2). Checks to confirm that there is at least one item on the stack and the top object on the stack is a number (either a binary number or a character string that convert to numbers). Stops without action (other than error report) if either test fails. |

pendown | pendown |

--- |

description |

penup | penup |

--- |

Lifts the turtle’s pen. Causes the turtle to stop drawing when it moves. |

pi | pi |

--- n |

Places pi (n) on the top of the stack (approximately 3.14). Also can use the actual character π. |

pop | pop |

any --- |

Pops the top object (any) from the stack. |

radianstodegrees | radians to degrees conversion |

n1|u1 --- n2 |

Checks to make sure there is at least one object on the stack and that the object on the top of the stack is numeric (either binary number or a character string that can be converted into a number). Stops without action (other than error report) if either test fails. If the object on the top of the stack is a valid number (n1 or u1), converts the number (n1 or u1) from radians to degree and pushes this answer (n2) to the top of the stack. |

resetgrafx | reset grafx |

--- |

Clears the canvas and resets the turtle to the initial drawing context (other than background color). |

right | right |

d --- |

Turns the turtle to the right. Expects the number of degrees to turn to the right to be the top item on the stack (d). Modulus 360 applies to the number. Negative numbers reverse the direction of the turn. |

setbackground | set background |

color --- |

Sets the color of the background in the canvas. Expects the new background color (color) to be on the top of the stack as a string in any of the three color formats accepted by JavaScript. |

show | show |

--- |

Shows the turtle. |

sin | sine |

n1|u1 --- n2 |

Checks to make sure there is at least one object on the stack and that the object on the top of the stack is numeric (either binary number or a character string that can be converted into a number). Stops without action (other than error report) if either test fails. If the object on the top of the stack is a valid number (n1 or u1), computes the trigonometric function of sin(n1), n1 being in radians and pushes this answer (n2) to the top of the stack. |

sqrt1/2 | pi |

--- n |

Places the square root of 1/2 (one half) (n) on the top of the stack (approximately 0.707). |

sqrt1_2 | pi |

--- n |

Places the square root of 1/2 (one half) (n) on the top of the stack (approximately 0.707). |

sub | subtract or subtraction |

num_{1} num_{2} --- difference |

Pops the top two items on the stack and subtracts them, then pushes the total (difference) to the top of the stack. The number on the top of the stack (num_{2}) is subtracted from the number second on the stack (num_{1}). **Example:** algebriac notation **3 - 2 =** would be converted into RPN (stack) notation **3 2 sub .** (answer is 1) Checks to confirm that both of the top two objects on the stack are numbers (either as binary numbers or as character strings that convert to numbers). Stops without action (other than error report) if either test fails or if there are less than two objects on the stack. |

swap | swap |

x1 x2 --- x2 x1 |

Swaps the top two objects (x1 and x2) on the stack. Checks to guaranatee that there at least two objects on the stack and stops with error if there are only one or zero items on the stack. Same functionality as PostScript’s **exch**. |

π | pi |

--- n |

Places pi (n) on the top of the stack (approximately 3.14). Also can use the word **pi**. |

This is part of an instructional series on the building of a Forth programming environment in any standard browser using JavaScript.

Threaded Interpreted Languages (TILs), including Forth, are designed for customization.

In addition to writing your own Forth programs, please modify the underlying engine to meet your specific needs.

Please have fun with this project. Make it your own.

**The most recent version is at stable release version or http://www.twiddledom.com/coder/js78.html**

return to Outrageous Coder
### contact

comments, suggestions, corrections, criticisms

because of ridiculous spam attacks,

contact through Twitter (@OutrageousCoder) will be more reliable than the contact form

Licensed under the MIT License. You may obtain a copy of the License at

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Names and logos of various OSs are trademarks of their respective owners.