music
OSdata.com: programming text book 

OSdata.com

reference manual

summary

OSdata RSS
News Feed


OSdata blog RSS.

OSdata blog RSS - add to Bloglines
OSdata blog RSS - add to Google Reader.
OSdata blog RSS - add to My AOL
OSdata blog RSS - add to Newsgator.

    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.

previous page   next page
previous page
turtle graphics
  next page
Outrageous Coder
Google

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.

wordnamelanguage
category
stack start --- stack end
description

 white spaceForth CORE/PostScript
separator
    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)Forth CORE
memory reference
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)Forth CORE
system
<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)Forth CORE
mathematics
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)Forth CORE
mathematics
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)Forth CORE
memory reference
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)Forth CORE
mathematics
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)Forth CORE
I/O
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.

.Sdot-sForth 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)Forth CORE
I/O
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)Forth CORE
mathematics
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)Forth CORE
mathematics
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)Forth CORE
mathematics
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 plusForth 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 minusForth 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 plusForth 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 minusForth 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)Forth CORE
mathematics
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 plusForth 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 minusForth 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 slashForth CORE
mathematics
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 plusForth 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 minusForth 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 plusForth 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 plusForth 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 minusForth 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 plusForth 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 minusForth 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 plusForth 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 minusForth 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 plusForth 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 minusForth 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 plusForth 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 minusForth 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.

absabs or absolute valueForth CORE/PostScript
mathematics
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.

addadditionPostScript
mathematics
num1 num2 --- sum
    Pops the top two items on the stack and adds the top number (num2) to the second to top number (num1), 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.

backback or backwardsTurtle Graphics
graphics
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.

clearclear stackPostScript
stack
<any> --- <empty>
    Removes everything from the stack.

clearcanvasclear canvasTurtle Graphics
graphics
---
    Clears the canvas to the current background color.

clearstackclear stackForth nonstandard
stack
<any> --- <empty>
    Removes everything from the stack.

degreestoradiansdegrees to radians conversiongeneric stack language
mathematics
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.

depthdepthForth CORE
stack
--- +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.

divdivide or divisionPostScript
mathematics
num1 num2 --- 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 (num2) is divided from the number second on the stack (num1). 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.

drawcircledraw circlegeneric stack language
graphics
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.

drawrectangledraw rectanglegeneric stack language
graphics
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.

dropdropForth CORE
stack
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.

dupduplicateForth CORE/PostScript
stack
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.

eEuler’s numbergeneric stack language
mathematics
--- n
    Places Euler’s number (n) on the top of the stack (approximately 2.718).

eqequal (equality test)PostScript
boolean, relational
any1 any2 --- bool
    Pops and compares the two top objects on the stack. If the second object on the stack (any1) is equal to the object on top of the stack (any2), 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).

exchexchangePostScript
stack
any1 any2 --- any2 any1
    Exchanges the top two objects (any1 and any2) 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.

executeexecuteForth CORE
system
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).

forwardforwardTurtle Graphics
graphics
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.

gegreater than or eqqual to (equality test)PostScript
boolean, relational
num1|string1 num2|string2 --- bool
    Pops and compares the two top objects on the stack. If the second object from the top of the stack (num1 or string1) is greater than or equal to the object on the top of the stack (num2 or string2), 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).

gtgreater than (equality test)PostScript
boolean, relational
num1|string1 num2|string2 --- bool
    Pops and compares the two top objects on the stack. If the second object from the top of the stack (num1 or string1) is greater than the object on the top of the stack (num2 or string2), 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).

herehereForth CORE
system
--- addr
    Pushes the numeric address of the next open memory cell location (addr) to the top of the stack.

hidehideTurtle Graphics
graphics
---
    Hides the turtle.

homehideTurtle Graphics
graphics
---
    Returns the turtle to the home position (normally the center of the canvas).

idivinteger dividePostScript
mathematics
num1 num2 --- 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 (num2) is divided from the number second on the stack (num1). 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.

leless than or eqqual to (equality test)PostScript
boolean, relational
num1|string1 num2|string2 --- bool
    Pops and compares the two top objects on the stack. If the second object from the top of the stack (num1 or string1) is less than or equal to the object on the top of the stack (num2 or string2), 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).

leftleftTurtle Graphics
graphics
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.

ln2natural logarithm of 2generic stack language
mathematics
--- n
    Places the natural logarithm of 2 (n) on the top of the stack (approximately 0.693).

ln10natural logarithm of 10generic stack language
mathematics
--- n
    Places the natural logarithm of 10 (n) on the top of the stack (approximately 2.302).

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

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

ltless than (equality test)PostScript
boolean, relational
num1|string1 num2|string2 --- bool
    Pops and compares the two top objects on the stack. If the second object from the top of the stack (num1 or string1) is less than the object on the top of the stack (num2 or string2), 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).

maxmaximumForth CORE
mathematics
n1|u1 n2|u2 --- n3
num1 num2 --- num3
    Pops the top item from the stack (n1 or u1 or num1) and the second item from the top (n2 or u2 or num2), then pushes the maximum (larger) of the two numbers (n3 or num3) 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.

minminimumForth CORE
mathematics
n1|u1 n2|u2 --- n3
num1 num2 --- num3
    Pops the top item from the stack (n1 or u1 or num1) and the second item from the top (n2 or u2 or num2), then pushes the minimum (smaller) of the two numbers (n3 or num3) 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.

modmodulusForth CORE/PostScript
stack
n1 n2 --- n3
int1 int2 --- 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 int2) is mod from the number second on the stack (n1 or int1). 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.

mulmultiply or multipicationPostScript
mathematics
num1 num2 --- product
    Pops the top two items on the stack and multiplies the top number (num2) by the second to top number (num1), 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.

nenot equal (equality test)PostScript
boolean, relational
any1 any2 --- bool
    Pops and compares the two top objects on the stack. If the second object on the stack (any1) is not equal to the top object on the stack (any2), 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).

negunary negate or unary negationPostScript
mathematics
num1 --- num2
    Negate the number on the top of the stack (num1), giving the arithmetic inverse (num2). 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.

negateunary negateForth CORE
mathematics
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.

pendownpendownTurtle Graphics
graphics
---
    description

penuppenupTurtle Graphics
graphics
---
    Lifts the turtle’s pen. Causes the turtle to stop drawing when it moves.

pipigeneric stack language
mathematics
--- n
    Places pi (n) on the top of the stack (approximately 3.14). Also can use the actual character π.

poppopPostScript
stack
any ---
    Pops the top object (any) from the stack.

radianstodegreesradians to degrees conversiongeneric stack language
mathematics
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.

resetgrafxreset grafxTurtle Graphics
graphics
---
    Clears the canvas and resets the turtle to the initial drawing context (other than background color).

rightrightTurtle Graphics
graphics
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.

setbackgroundset backgroundTurtle Graphics
graphics
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.

showshowTurtle Graphics
graphics
---
    Shows the turtle.

sinsinegeneric stack language
mathematics
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/2pigeneric stack language
mathematics
--- n
    Places the square root of 1/2 (one half) (n) on the top of the stack (approximately 0.707).

sqrt1_2pigeneric stack language
mathematics
--- n
    Places the square root of 1/2 (one half) (n) on the top of the stack (approximately 0.707).

subsubtract or subtractionPostScript
mathematics
num1 num2 --- 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 (num2) is subtracted from the number second on the stack (num1). 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.

swapswapForth CORE
stack
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.

πpigeneric stack language
mathematics
--- 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 computer programming lessons
return to Forth in JavaScript
return to Source Code Examples


return to Outrageous Coder
previous page   next page
previous page
turtle graphics
  next page
Outrageous Coder

contact
comments, suggestions, corrections, criticisms

because of ridiculous spam attacks,
contact through Twitter (@OutrageousCoder) will be more reliable than the contact form

please contact us

your name:
email address:
phone number:
message:

return to table of contents
free downloadable college text book

license

    This is example code from OSdata, This Side of Sanity, and Twiddledom, released under the MIT License.

    Copyright © 2014, 2015 Milo

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

        http://opensource.org/licenses/MIT

    The MIT License (MIT)

    Copyright © 2014, 2015 Milo

    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.

previous page   next page
previous page
turtle graphics
  next page
Outrageous Coder

Google


Made with Macintosh

    This web site handcrafted on Macintosh computers using Tom Bender’s Tex-Edit Plus and served using FreeBSD .

Viewable With Any Browser


    †UNIX used as a generic term unless specifically used as a trademark (such as in the phrase “UNIX certified”). UNIX is a registered trademark in the United States and other countries, licensed exclusively through X/Open Company Ltd.

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

    Copyright © 2015 Milo

    Created: May 5, 2015

    Last Updated: May 5, 2015


return to table of contents
free downloadable college text book

previous page   next page
previous page
turtle graphics
  next page
Outrageous Coder