Yet another toy language written in haskell. Inspired by Forth and Lisp.
1 // Int
"string" // String
0.5 // Double
(1 2 3 * + -) // Lambda
'x // Symbol
x // Word
1 2 + // -> 4
5 'x def // -> set "x" to 5
(1 +) 'succ def // Define the 'function' "succ"
"Hello world" print // print 'hello world'
(2 *) // add the 'lambda' (2 *) to the stack.
5 stack // (5)
5 (2 +) eval // 7
"string" (1 2) (+) push // "string" (1 2 (+))
(1 2) (3) cons // (1 2 3)
(1 2) (drop) cons // (1 2 drop)
(1 2) drop // -> empty
1 5 cons // -> (1 . 5)
(3 4) eval // -> 3 4
So 1 5 (+) eval
is equal to 1 5 +
. And apply
executes the stack on the next stack item
The language has two paralell stacks. One "data stack" and one "program stack". When the program is parsed. The entire program is added to the program stack. And the data stack is empty. Anything that is evaluated from the program stack is automatically added to the data stack.