Cantor programs can be split across multipleDocumentation 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.
.cantor files. The import directive loads all function definitions from another file into the current interpreter, letting you build libraries of reusable helpers and compose them freely.
The import directive
SyntaxIDENTIFIER is the file stem (name without .cantor) of the file to load. The directive must appear after the optional extended directive and before any functionDef blocks.
Example:
import anterior, it resolves the path to anterior.cantor in the same directory as the running program file, parses it, and merges all its define blocks into the current function environment.
What gets imported
When a file is imported, only its function definitions are loaded. Specifically:- All
defineblocks from the imported file are added to the interpreter’s function registry. - If the imported file itself contains
importdirectives, those transitive imports are resolved recursively using the same rules. - If the imported file contains an
extendeddirective, extended mode is enabled for the entire program — importing a file that usesextendedis equivalent to having writtenextendedin the main file. - The
maindirective of an imported file is ignored. Imports are function libraries, not programs — only the top-level file’smaindirective determines the entry point.
Import resolution
The path forimport foo is resolved as:
Circular import handling
The interpreter tracks every file it has already loaded by absolute path. If the same file is encountered a second time (whether directly or through a chain of transitive imports), it is silently skipped. This prevents infinite recursion and duplicate definitions when two files both import the same shared library.Example: signe.cantor imports anterior.cantor
Both files live intests/programs/phase2-imports/. Here are their contents in full:
anterior.cantor — defines the predecessor function:
Interpreter loads signe.cantor
main signe sets the entry point. The interpreter sees import anterior.anterior.cantor is parsed
aparella_amb_1 and anterior are registered. The main anterior directive in the imported file is ignored.signe.cantor's definitions are registered
aparella_amb_anterior and signe are added to the function registry.signe works:
aparella_amb_anteriorappliespair id anterior: gives<x.anterior(x)>=<x.max(0,x−1)>.signeappliescomp diff aparella_amb_anterior: computesdiff(<x.max(0,x−1)>)=max(0, x − max(0, x−1)).- For
x = 0:diff(<0.0>)=0. ✓ - For
x = 5:diff(<5.4>)=1. ✓
- For
File-not-found behaviour
If the interpreter cannot locate the imported file, it raises a runtime error:Transitive extended mode
Because importing anextended file propagates extended mode, a program that does not itself declare extended can inadvertently gain access to compair and primrec if it imports a file that does. This is intentional: it allows shared libraries to use extended combinators without forcing every consumer to redeclare the mode.
If you want to ensure your program does not use extended features, do not import any file that contains the
extended directive.