The stack
In French, the word « tourniquet » refers to various turning/revolving implements, like carousels, revolving doors, and turnstiles. In the tourniquet programming language, there are no variables. Instead, tourniquet programs revolve around the stack, which acts as a revolving door that takes in, spits out, and rearranges values. In tourniquet, the use of the stack is implicit; all functions simply operate on the stack, and nothing else.
In fact, a tourniquet program is merely a sequence of zero or more functions. The functions are evaluated in the order of their sequence, and that’s it. Take, for example, this trivial function definition in tourniquet, which simply adds one to the number on the top of the stack:
add_one := 1 + ;
Here, we define (using the :=
syntax) a function called add_one
. In the
body of the definition, 1
is the name of a function that pushes the
integer 1 onto the top of the stack.
And +
is the name of yet another function, which adds together the two
topmost values on the stack. The ;
merely ends the definition. We can
visualise add_one
like so, assuming that we already had 2 on top of the
stack:
┄┄┄┲━━━┓
… ┃ 2 ┃
┄┄┄┺━━━┛
↓ 1
┄┄┄┲━━━┳━━━┓
… ┃ 2 ┃ 1 ┃
┄┄┄┺━━━┻━━━┛
↓ +
┄┄┄┲━━━┓
… ┃ 3 ┃
┄┄┄┺━━━┛
Here, we’re using …
to represent everything that is on the stack, but isn’t
close enough to the top of the stack for us to actually care. This sequence of
stack visualisations goes from our initial state (2 is on top), to the state
after applying the 1
function (1 is on top, with 2 just below it), to the state after applying the
+
function (3 is on top).