In the Thun dialect of Joy there are only four kinds of things:
When the interpreter encounters a literal value (an integer, Boolean, or list) it is put onto the stack:
1 2 3 true false [4 5 true []]
When symbols are encountered they are looked up in the dictionary and the function they denote is evaluated:
cons
There is a special function trace
that will print a trace of the evalutation of an expression step-by-step. (It's like the i
combinator with side-effects):
[cons] trace
Let's see some other functions.
[pop unit ccons]
trace
sum
clear
Control flow is achieved by special functions called combinators that accept quoted expressions on the stack and prefix them in various ways to the pending expression. The four core combinators are:
branch
- do one thing or another based on a condition.loop
- do one thing over again (or not.)fork
(do things independently of each other, parallel.)23
dup 0 < [] [0 swap -]
[branch] trace
neg
[dup 0 < [] [0 swap -] branch] trace