StackLang Documentation

StackLang is a stack-based programming language with simple evaluation rules. StackLang is statically typed, meaning that commands and functions check the number and type of inputs before being evaluated. The language is also turing complete, since it supports function application and abstract functions. The interpreter is currently implemented in C++.

Using the Documentation

In these files, text is sometimes formatted like this. The altered formatting indicates that the text is either interactions with the interpreter or not normal prose in some way. When discussing interactions with the interpreter, both inputs and outputs are given as how they would appear when printed. Booleans are written as true or false, commands <like-this>, numbers 12/34, strings "like this", substacks << "with content here", "and maybe more content" >>, the special empty substack << (empty) >>, and types Type. Additionally, some text is formatted like this. The formatting indicates that the text is supposed to be a raw keystroke, combination of keystrokes, or raw input to the interpreter.

Terminology

Throughout this documentation, certain terms have special meanings. These are documented below.

  • function: synonym for command. A command is a stack element of type Command that is executed when on the top of the stack. It is preferred to use command for primitives (or both primitives and user-defined commands), and function for used-defined commands.
  • active end: the end of the stack that can be operated on. The terms "top" and "bottom" are strictly forbidden, since the visual layout of the interpreter means that "top", in the technical sense, actually refers to the bottom of the screen. The active end of a substack (or any horizontally-oriented list) is the left side. The active end of a vertically-entered substack is the top.

Notation

When discussing a command, a signature will often be mentioned. Signatures are formatted as a function name, a colon, then a list of space-separated input types, followed by a ->, followed by another list of space-separated output types. For example:
add : Number Number -> Number
is the signature for the command add. The left hand side is the side closer to the active end of the stack. The side closer to the active end is also the side from which paramters are numbered. The first paramter would be the number closest to the active end, and so on. Occasionally, commands will be missing either an input, and output, or have multiple outputs. Example:
define : Substack(Type) Substack Command ->
is the signature for define. Functions and commands will always pop their parameters off of the stack, so foo? : Any -> Any Boolean will still pop one element off of the stack, before pushing it back on, then pushing back on a Boolean as well. Finally, Substacks, numbers, and commands can have additional information attached to them. For example, a Substack(Number) is a substack that may only contain numbers. More detail on type specializations is given in the types section.

About the Author

StackLang, and the interpreter, is written and designed by Justin Hu.
LinkedIn
GitHub
Bug reports
Other Issues