About frtm
Frtm (FoRTh Modoki) is a software that simulates the programming language FORTH. However it is not intended to reproduce the strict FORTH. There is no compiler, but the words and the constants in a user-defined word are interpreted when it is registered.
There are also some aspects unlike FORTH: frtm does not have the words to manipulate the return stack, whereas frtm allows the recursive definition of the word.
Frtm also supports the calculation of real numbers. It has mathematical functions like exponential, square root, trigonometric functions, hyperbolic functions, bitwise operations. So frtm can be the alternative software of scientific calculator.
Interpretation of the expression will be conducted in accordance with Reverse Polish Notation (RPN). Frtm has conditional branch "if", structure for a loop "do-while" and "for-loop". You can also make a new word by combining the word.
On the Android OS, the configuration of the initial size of the dictionary and the stack, the ability to save the word in the dictionary to the "word book" have been added. The number of "word book" is limited to up to three.
For a more detailed specification of the language, please refer to the Web page in Japanese for support.
If you want to test frtm freely, please try Java applet version of frtm at following web page:
http://www.rbt.his.u-fukui.ac.jp/~naniwa/comp/frtma.html
*** EXAMPLES of words ***
* Average of two numbers
: ave + 2.0 / ;
* Average of N numbers
: nave swap over 1 for rot + loop swap 1.0 * / ;
2 4 6 8 10 5 nave . cr
0 1 2 3 4 5 6 7 8 9 10 SP nave . cr
* Population variance of N numbers
: nvarp dup 1+ copy nave SP nrotr swap dup * over 1 for rot dup * + loop swap 1.0 * / SP nrot dup * - ;
2 4 6 8 10 5 nvarp . cr
* Unbiased variance of N numbers
: nvar dup 1+ copy nave SP nrotr swap dup * over 1 for rot dup * + loop SP nrot dup * 3 ndup * - swap 1- 1.0 * / ;
2 4 6 8 10 5 nvar . cr
* Greatest common divisor of 2 numbers
: gcd do swap over % dup 0 > while drop ;
1001 819 gcd . cr
* Factorial [fact(1) = 1, fact(n) = n*fact(n-1)]
** Recursion
: factr dup 1 = if else dup 1- factr * endif ;
10 factr . cr
** Iteration
: facti 1 swap 1+ 1 for I * loop ;
10 facti . cr
* Fibonacci sequence [fib(0) = 0, fib(1) = 1, fib(n) = fib(n-1) + fib(n-2)]
** Recursion
: fib dup 0= if else dup 1 = if else dup 1- fib swap 2 - fib + endif endif ;
30 fib . cr
** Iteration
: fibi dup 0= if else 0 1 rot 1 for swap over + loop swap drop endif ;
30 fibi . cr
* Graphics
** Fill rectangle
: boxes 16 0 for I setcol 10 20 I * + dup 100 100 rectf loop ;
gm boxes
: hls 16 0 for I 45 * 2 / 50 100 setHLS 10 20 I * + dup 100 100 rectf loop ;
gm hls
** Recursive Drawing (Koch curve)
: pre 5 copy drop ;
: genx 3 ndup 6 ndup - * minus 100 / swap 4 ndup 7 ndup - * 100 / + 5 ndup +
5 nrotr 4 ndrop ;
: geny swap 3 ndup 6 ndup - * 100 / swap 4 ndup 7 ndup - * 100 / + 4 ndup +
5 nrotr 4 ndrop ;
: gen 6 copy genx 7 nrotr geny ;
: keep 7 nrotr 7 nrotr pre ;
: post 9 nrot 9 nrot 4 nrot 4 nrot 5 ndup 1- ;
: line moveto lineto ;
: koch dup 0= if drop line else
pre 0 0 gen keep 33 0 gen post koch
pre 33 0 gen keep 50 -28 gen post koch
pre 50 -28 gen keep 66 0 gen post koch
pre 66 0 gen keep 100 0 gen post koch
5 ndrop
endif ;
: kochs 10 setcol 89 440 551 440 4 koch
11 setcol 551 440 320 40 4 koch
12 setcol 320 40 89 440 4 koch ;
gm kochs
** Direct use of ReGIS graphics terminal like escape sequence
gm
(W(I15)P[50,50]C(S)[][+40,+40][+40,-40][+40,+40][+40,-40][+40,+40][+40,-40][](E)) .
(W(I12)P[50,150]F(C(B)[200,+200][+200,-150](E))) .
(W(I11)P[70,170]T(S16)[16,12]'Hello World') .
// By using the word 'grdemo', some words for examples of graphics will be registered in to the dictionary.