This guide assumes you have already cloned the repository, installed the Python dependencies, and generated the ANTLR4 parser files. If you haven’t done that yet, complete the Installation steps first, then come back here.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/felipenugo/cantor-interpreter/llms.txt
Use this file to discover all available pages before exploring further.
All commands below are run from the root of the
cantor-interpreter repository.Run your first program
The simplest possible Cantor program issuma.cantor. Its entire source is:
main keyword declares which function the program exposes. Here it is the built-in add, which receives a Cantor-encoded pair <x, y> and returns x + y.
Run it by piping two numbers into the interpreter:
What just happened?
- You provided two numbers,
3and2, on standard input. - The interpreter read them and encoded the pair using the Cantor pairing function:
<3, 2>becomes a single natural number. - The
mainfunction (add) received that encoded number, decoded the pair, and returned3 + 2 = 5. - The result was printed to standard output.
A program with definitions
anterior.cantor defines a predecessor function (called anterior — Catalan for “previous”). Because the language has no subtraction that can go negative, it implements max(0, x − 1) using the built-in diff combinator:
aparella_amb_1usespair id k_1to turn inputxinto the Cantor pair<x, 1>.anteriorappliescomp diff aparella_amb_1, meaning it first runsaparella_amb_1on the input to get<x, 1>, then feeds that todiff, which computesmax(0, x − 1).
Program structure reference
Every.cantor file follows this layout (only main is required):
main <function>— declares the entry-point function. Must appear exactly once.import <module-name>— imports definitions from a file named<module-name>.cantorin the same directory as the current program.extended— unlocks thecompairandprimreccombinators.define <name> [doc] <body>— gives a name to a function expression. The documentation string in[…]is required by the grammar and ignored at runtime — it exists to annotate what the function does.
CLI usage
The interpreter always reads from standard input and writes the result to standard output:Write and run your own program
Write the program
Add the following content. This defines a
double function that computes x + x by pairing x with itself and passing the result to add. Because each combinator body only accepts plain function names, the intermediate pair id id step must be given its own name first:pair_x_xusespair id idto turn inputxinto the Cantor pair<x, x>.doubleappliescomp add pair_x_x, meaning it first runspair_x_xon the input to get<x, x>, then feeds that toadd, yieldingx + x.