Skip to content

Functions and Scope

A function declaration stores a name, a parameter list, and a body. It does not store a value, and a program cannot pass a function around. The name is entered when the declaration runs, so a call that appears earlier in the file is a name error.

A call checks that the number of arguments matches the parameters, then builds a fresh local environment whose parent is the file's globals. The body walks in that local environment. return is an internal signal carrying the value. A body that finishes without return , and a bare return , both produce null .

Globals

Looking up a name checks the local environment and then the parent. That is how a function reads a global. An assignment looks only at the local environment. If the name exists solely on the parent, the assignment is a runtime error. The function must let the name itself, or receive it as a parameter. A conditional or a loop does not add another environment, so a let inside one of those blocks belongs to the function, or to the file when it is outside a function.

Recursion

Each Lupe call increments a depth counter on the shared runtime and pushes a trace frame. The limit is 1000 Lupe calls. The frame records the function name, the caller's file, and the call's line, which is what an error prints after the source line.

The walk is recursive Python calls, and each Lupe call keeps several Python frames alive. Before execution starts, the interpreter raises CPython's recursion limit when it is too low. The error a deep program sees is the Lupe limit, with its trace.