1 2 + . ; 3
(* 2) . ; 6
@x ; empty | x=6
2 x * . ; 12
stack based programming language. stack value types: bool, num, func/body, seq, set, obj.
- bool: one bit value (T F)
- num variants: nat (0 1..), int (±nat), rat (int/nat), real (floating point number), comp (real-i-real)
- func: native function
- body: knot constructed "function" (internal code execution on stack)
- seq: tuple of values
- obj: binary map of words to values and binary set of values at the same time context is scope based variable mapping.
T (1 2 +.) ? ; 3
F (1 2 +.) ? ; empty
boolean values are distinct from numbers and can not interoperate with them unless type casted. ? takes in the top two values (a b) and applies b like . if a is true (T), without a on the stack. if a is false (F), then the two values are just taken from the stack without any application.
0 ; nat
-1 ; int
1/3 ; rat
3.1416 ; real
1.5i2.1 ; comp
all numbers are interoperational, while outputing the max number class of the bunch.
+ - * / %
& | << >>
and nand or nor
eq neq <= >= ; a b -> c
~ not # ; a -> b
these are native functions with arithmetic, logic, and comparison binary operations, as well as the unary counter parts. the are applied with ..
() ; does nothing
(2 *) ; multiplies top value with two
(@a a a) ; duplicates top value
(@(a b) b a) ; swaps top two values
(@(a b c) b c a) ; rotates top three values
bodies are scopes parts of code that are treated as values and can be applied with ., like functions. variables can be caught anywhere in the current local scope by prefixing the word with @, where the value is taken from the stack. @(...) captures stack values in order from the lowest on the stack to the top value.
1 2 3 @a @b @c ; a=3, b=2, c=1
1 2 3 @(a b c) ; a=1, b=2, c=3
[ 1 1 1 +. , 2 *. ]
gives back a sequence of values (1, 2, 4) taken from it's locally offset stack to the top. , duplicates the top value
{ 1 @a 1 1 +. @b b 2 *. @c }
{ 1 1 1 +. , }
gives back an object with a=1, b=2, and c=4, as it is just a code body where the map of it's scope get to be the words. the second is a set. an object is both at the same time