Husband, father, kabab lover, history buff, chess fan and software engineer. Believes creating software must resemble art: intuitive creation and joyful discovery.
Views are my own.
Besides the fun of stretching your mental muscles to think in a different paradigm, Forth is usually used in the embedded devices domain (like that of the earlier Mars rover I forgot the name of).
This project for me is mostly for the excitement and joy I get out of implementing a Forth (which is usually done in Assembler and C) on the JVM. While I managed to keep the semantics the same the underlying machinery is vastly different from, say, GForth. I find this quite a pleasing exercise.
Last but not least, if you like concatenative but were unable to practice fun on the JVM, bjForth may be what you’re looking for.
Hope this answers your question.
Not really I’m afraid. Effects can be anywhere and they are not wrapped at all.
In technical terms it’s stack-oriented meaning the only way for functions (called “words”) to interact with each other is via a parameter stack.
Here’s an example:
TIMES-10
is a word which pops one parameter from stack and pushes the result of its calculation onto stack. The( x -- y)
is a comment which conventionally documents the “stack effect” of the word.Now when you type
12
and press RETURN, the integer 12 is pushed onto stack. ThenTIMES-10
is called which in turn pushes10
onto stack and invokes*
which pops two values from stack and multiplies them and pushes the result onto stack.That’s why when type
.S
to see the contents of the stack, you get120
in response.Another example is
This simple example demonstrates the reverse Polish notation (RPN) Forth uses. The arithmetic expression is equal to
5 * (20 - 10)
the result of which is pushed onto stack.PS: One of the strengths of Forth is the ability to build a vocabulary (of words) around a particular problem in bottom-to-top fashion, much like Lisp. PPS: If you’re ever interested to learn Forth, Starting Forth is a fantastic resource.