Module Bodies
Every module includes a module body. A module body is a lexical container of Avail source code, and as such comprises a sequence of top-level statements. The body of a module begins immediately after the keyword Body, which must always be the last keyword to occur within a module header.
A statement that occurs directly within a module body, rather than recursively with function definitions, is called a top-level statement. Following is an enumeration of the legal top-level statements:
- A macro send that answers a statement:
- A top-level variable declaration (
"…:_†;"or"…:_†:=_;") introduces a module variable. A module variable is a mutable location that is able to store instances of a declared type. A module variable has module scope: it is visible to every expression within the module that occurs lexically after its definition (unless shadowed by a parameter, local variable, or local constant). The extent of a module variable will generally outlast its scope, since a module variable will typically be closed into a method definition. - A top-level constant definition (
"…::=_;") introduces a module constant. A module constant is permanently bound to a specific value. A module constant has module scope. The extent of a module constant will generally outlast its scope, since a module constant will typically be closed into a method definition. - An assignment (
"…:=_;") of a new value to a module variable. - An sequence is an immutable, ordered list of statements. A macro send can extend to multiple statements by answering a sequence.
- An expression-as-statement that decorates an expression.
- A top-level variable declaration (
- A message send of a ⊤-valued method definition. Method definers — like
"Method_is_","Semantic restriction_is_","Grammatical restriction_is_", and"Seal method_at_"— and object type definers are the most common top-level message sends.
Below is a sample module, Fibonacci. Its body constitutes everything following the Body keyword, i.e., lines 37-74.
In practice, message sends are the most common top-level statements, followed by module constant definitions. Module variable declarations are rare, occurring in only a few modules of the Avail standard library. Top-level assignments are extremely rare; they never occur in the Avail standard library.
| ‹ Module Resolution | | | Return to Modules | | | Name Resolution › |