quiltro.org

Multi-stack concatenative programming

This page is a work in progress. Here be dragons.

Multi-stack concatenative languages give you several named stacks instead of one, and words declare which stacks they read from and write to.

Word specialization over stacks

Words can be generic over the stacks they touch. Given a word my-word with a signature of:

my-word :: { work: [ ..R a -> ..R b ], ... }

The work stack in the context of the word can be chosen freely by its caller, by means of specialization.

my-word               \ uses the work stack
my-word[~work:retain] \ uses the retain stack

This allows for words like >r, r> and the same shape for different stacks to be implemented as regular words, given a primitive move:

move :: { a: [ ..R a -> ..R ], b: [ ..R -> ..R a ] }

>r :: { work: [ ..R a -> ..R ], retain: [ ..R -> ..R a ] }
define >r { move[~a:work ~b:retain] }

Moreover, if the word only uses the one stack, one can elide its name in the specialization:

my-word[retain] == my-word[~work:retain]