Pancode - Syntax

Pancode is mostly whitespace-insensitive, as most commands are a single character in length. Anything which is not subject to the below rules is simply treated as a symbol command, i.e. an individual single-character command. Note that this applies to characters which do not have an assigned command yet, and in this case it is an error to execute such a nonexistent command.

Whitespace

There are no commands whose name consists of whitespace. All whitespace characters are skipped over during parsing.

Comments

Comments in Pancode begin with « and end with ». The delimiting characters can be nested within the comment. Any text inside a comment will be ignored.

Numbers

Integers may be written directly into Pancode and will resolve to special commands which push themselves onto the stack. An integer is defined to be an optional minus sign, followed by at least one decimal digit. Note that the entire integer must be contiguous and not contain whitespace within it, or else it will be seen as multiple tokens by the parser.

There are also three special numerical constants: (for infinity), - (for negative infinity), and 👿 (for NaN).

There is currently no way to input literal non-integers into Pancode source. This functionality may be added in the future. In the meantime, there are several commands to push common fractions (namely, the vulgar fraction characters such as ½).

Strings

String literals are denoted, as usual, with quotation marks ". Between the quotation marks, everything on the inside (including whitespace and newlines) is treated as part of the string contents. Backslash escape sequences may be used. Currently, \n (newline), \" (literal quote), and \\ (literal backslash) are the only supported escape sequences.

Functions

Functions are provided by wrapping the relevant code in square brackets [ and ]. A function, when executed, pushes itself onto the stack. A function on the stack can be called in several ways, the most direct being the call $ command.

Note that if you try to pretty-print a function (such as with .), you will get a literal which, if run as Pancode source, will behave identically when called to the function used to produce it. However, the two functions may or may not compare equal, especially in the case of functions produced by (curry) or (compose), which internally use more efficient representations.

As a special shortcut, if you want to construct a function which consists of exactly one command, you may do so by preceding the command with a backtick `. So, for instance, is equivalent to [×]

Slips

Enclosing a block of code in corner brackets ( and ) creates a Slip. Slips are sort of like functions, in that they store blocks of code to be executed. However, a slip immediately executes when evaluated, so a sequence of commands inside of a slip behaves equivalently to the same commands without the slip.

You'll seldom use slips directly, but they come up as a result of macro-style expansion code sometimes.

Global Variable Commands

The two characters and are treated specially. When one of these characters is encountered, the next non-whitespace character is consumed as well and treated as a variable name. Then a single command is created, which assigns to or reads from the variable with the given name.

For technical reasons, the following characters cannot be used as variable names: ", -, , 👿, ASCII digits, whitespace, and comment delimiters (« and »)

The global variable characters are just syntax sugar, to make calling the global variable commands more convenient. If X is a valid variable identifier, then →X behaves identically to 'X ↲, and ←X behaves identically to 'X ↳.

Quoted Commands

A single ' apostrophe causes the next command to be treated specially. The apostrophe and the following command form a composite command which, when evaluated, simply pushes the given value to the stack. If the following command is a symbol, this pushes the symbol (and all attached modifiers) rather than evaluating it as a plain symbol command would. If the following command is a string or numerical literal, this pushes the string or number.

The runtime representation of a quoted command is a box. That is, the expression ''a, when evaluated, will push a box containing the symbol a onto the stack. It is equivalent, at runtime, to the expression 'a ⊂.

The command following ' shall not be an assignment to or query from a global variable. If it is, the behavior is undefined. This behavior may be specified in a future version of Pancode.

Modifiers

Every symbol command is succeeded by zero or more modifiers, which in some cases may change the behavior of the command. There are currently two types of modifiers in Pancode. The first is numerical modifiers, supplied as numbers from 0 to 20 using the characters . The second is prime modifiers, supplied using the character.

Note that only symbol commands can have modifiers. It is a syntax error to have a modifier attached to a number, string, global variable assignment, or any other kind of command.

Documentation Index