For ease of implementation, I think we should make it an error for an imported identifier to be referenced or defined in a library before the library declaration that imports it. This allows strict left-to-right processing of library declarations, with no need to delay processing till the end of the library.
Therefore, this would be an error (but still permitted as an extension in Schemes that can easily provide it):
(module (begin (define x y)) (import (library defining y))This would necessitate replacing the penultimate paragraph of section 5.5.1 with:
One possible implementation of libraries is as follows: After all cond-expand library declarations are expanded, a new environment is constructed for the library consisting of all imported bindings. The expressions and declarations from all begin, include, and include-ci declarations are expanded in that environment in the order in which they occur in the library declaration. Alternatively, cond-expand and import declarations may be processed in left to right order interspersed with the processing of expressions and declarations, with the environment growing as imported bindings are added to it by each import declaration.
WG1 decided to adopt this limitation.
Incremental processing is the way Chicken modules (which are just name scopes) work today, and it seems a plausible approach to allow.