Tower is a simple stack-based language.
Tower has 4 primitive types:
A function is defined by a
:=, followed by a space, then a name for the function, and then the operations to perform, separated by spaces. An operation of
end terminates the function defininiton.
For example, to define a function called
square that squares the top number on the stack, you might do:
:= square dup * end
In Tower, you can push a function onto the stack. The syntax for doing this is
Thanks to this mechanism, conditionals are merely a pair of functions on the stack, a boolean, and a call to
In practice, this looks like:
' truefunc ' falsefunc True if
This will call truefunc. If the conditional were False, it would call falsefunc.
Using this conditional and recursion, you can accomplish terminatable looping.
In addition to function literals, you have:
There are two types of comments in Tower: inline comments and until-end-of-line comments
An inline comment begins with the character
( and continues until it reaches a
An until-end-of-line comment begins with the character
# and continues until the end of the line.