Hello again.
I have been thinking about how to implement the syntactic tower in a simple but correct way. What I have come up with is this: In a module, there are different environments, one for each different phase of evaluation (runtime, macro expansion time, macro macro expansion time and so on). (This is not a new invention in any way. I just hope that I have copied the concepts correctly.)
If you write normal code with no macros, only environment with phase 0 is into play. You get into the next phase in macro definitions or by using the syntax-begin form:
(import srfi-1)
(syntax-begin (import srfi-13))
(define (a-function) ;; This is inside environment phase 0. ;; Things from srfi-1 are available, but not things from srfi-13. fold)
(define-macro (a-macro) ;; Because this is macro definition, this is inside environment phase 1. ;; Things from srfi-13 are available, but not things from srfi-1
(define-macro (an-inner-macro) ;; This is inside environment phase 2. ;; Neither srfi-1 nor srfi-13 are imported in this environment. "hello world")
(string-titlecase (an-inner-macro)))
The module system's runtime functions (for instance expand-macro and syntax-rules) are available at the REPL and at all environments whose phase >= 1. It's possible to use the module system's runtime in modules' functions, but then you have to explicitly import the module system.
This is to make it clear that unless explicitly noted, compiled code is not dependent on the module system. This also makes it easier to tell which modules need to be loaded when compiling a module.
Does this make sense? Or am I trying to solve a non-problem? Is this overly difficult to understand?
/Per