Previous: , Up: scheme library form   [Index]


3.7.1.7 Library bodies

The ?library-body of a library form consists of forms that are classified as definitions or expressions. Which forms belong to which class depends on the imported libraries and the result of expansion. Generally, forms that are not definitions are expressions.

A ?library-body is like a ?body except that a ?library-bodys need not include any expressions. It must have the following form:

?definition?expression

When begin, let-syntax, or letrec-syntax forms occur in a top–level body prior to the first expression, they are spliced into the body. Some or all of the body, including portions wrapped in begin, let-syntax, or letrec-syntax forms, may be specified by a syntactic abstraction.

The transformer expressions and bindings are evaluated and created from left to right, as described in Expansion process The expressions of variable definitions are evaluated from left to right, as if in an implicit letrec*, and the body expressions are also evaluated from left to right after the expressions of the variable definitions. A fresh location is created for each exported variable and initialized to the value of its local counterpart. The effect of returning twice to the continuation of the last body expression is unspecified.

NOTE The names ‘library’, ‘export’, ‘import’, ‘for’, ‘run’, ‘expand’, ‘meta’, ‘import’, ‘export’, ‘only’, ‘except’, ‘prefix’, ‘rename’, ‘and’, ‘or’, ‘not’, ‘>=’, and ‘<=’ appearing in the library syntax are part of the syntax and are not reserved, i.e., the same names can be used for other purposes within the library or even exported from or imported into a library with different meanings, without affecting their use in the library form.

Bindings defined with a library are not visible in code outside of the library, unless the bindings are explicitly exported from the library. An exported macro may, however, implicitly export an otherwise unexported identifier defined within or imported into the library. That is, it may insert a reference to that identifier into the output code it produces.

All explicitly exported variables are immutable in both the exporting and importing libraries. It is thus a syntax violation if an explicitly exported variable appears on the left–hand side of a set! expression, either in the exporting or importing libraries.

All implicitly exported variables are also immutable in both the exporting and importing libraries. It is thus a syntax violation if a variable appears on the left–hand side of a set! expression in any code produced by an exported macro outside of the library in which the variable is defined. It is also a syntax violation if a reference to an assigned variable appears in any code produced by an exported macro outside of the library in which the variable is defined, where an assigned variable is one that appears on the left–hand side of a set! expression in the exporting library.

All other variables defined within a library are mutable.


Previous: , Up: scheme library form   [Index]