min is a stack-based, concatenative programming language that uses postfix notation. If you already know Forth, Factor or Joy, or if you ever used an RPN calculator, then min will look somewhat familiar to you.
If not, well, here’s how a short min program looks like:
; This is a comment (1 2 3 4 5) (dup *) map
This program returns a list containing the square values of the first five integer numbers:
(1 4 9 16 25)
Let’s see how it works:
- First a list containing the first five integer is pushed on the stack.
- Then, another list containing two symbols (
*) is pushed on the stack. This constitutes a quoted program which, when executed duplicates the first element on the stack —this is done by
dup— and then multiplies —with
*— the two elements together.
- Finally, the symbol
mapis pushed on the stack. Map takes a list of elements and a quoted program and applies the program to each element.
- There are no variable assignments.
- elements are pushed on the stack one by one.
- Parentheses are used to group together one or more elements, so that they are treated as a single element and they are not evaluated immediately.
- Symbols (typically single words, or several words joined by dashes) are used to execute code that performs operations on the whole stack.
Unlike more traditional programming languages, in a concatenative programming language there is no inherent need of variables or named parameters, as symbols acts as stack operators that consume elements that are placed in order on top of a stack.
→ Continue to Data Types