Skip to content

Modules and the REPL

An import loads another Lupe file and runs it. The loader resolves the string relative to the file that contains the import, and the name must end in .lupe . The filename stem becomes the module name, so import "maths.lupe" creates the name maths . That stem has to be a usable identifier. It cannot be a keyword or a built-in name.

One Run, One Environment

The imported file is executed in its own global environment. Its functions and constants are read through the module name, as in maths.add(10, 20) . The file does not see the importer's locals, and the importer does not see the module's names except through that prefix.

The loader remembers each resolved path. A second import of the same file returns the module that already ran. While a file is still running, the path sits in a loading set. Finding it there again is a circular import, reported against the import statement.

Every module shares one runtime. Standard input, standard output, the script arguments, the call depth, and the trace are common. The globals are not. A print in a module writes to the same stream as the main file, and a recursive call that crosses a module still counts toward the one limit.

The Session

lupe repl builds one interpreter and reuses it. A complete submission is parsed and walked. A trailing expression is printed. A submission that stops mid-statement, with the incomplete flag set by the parser, keeps the buffer and prompts with ... . Any other error is printed and the session continues, including the variables and functions already defined.

exit(code) leaves the session with that status. End of input after a finished line ends the session with status 0. End of input while a block is still open is a syntax failure and status 3.