[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: need help with macros (again)



At Wed, 10 Apr 2002 18:18:32 -0400 (EDT), Doug Orleans wrote:
>   (module env mzscheme
>     (provide make-environment-syntax [...])
>     [...]
>     (define (make-environment-syntax stx)
>       (let ((fv (free-variables-syntax stx)))
> 	(with-syntax (((var ...) fv))
> 	  (syntax (lambda (msg)
> 		    (case msg
> 		      ((var) var)
> 		      ...
> 		      ))))))
>    [...]
> 
>   )
>
> [...]
> 
>   (module keep-source mzscheme
>     (require-for-syntax env)
>      [...]
>   )
> 
>  [...]
>
>   > (require keep-source)
>   > (define foo (let ((x 3)) (lambda (y) (+ x y))))
>   proc-info.scm:9:9: compile: bad syntax; function application is not allowed, 
> because no #%app syntax transformer is bound in: (lambda (msg) (case msg ((+) 
> +) ((x) x)))
> 
> What's going on here?

The `env' module imports MzScheme at both run time and compile time.
Let's call run time "phase 0" and compile time "phase 1".

The `keep-source' module import `env' for syntax. As a result, phase 1
expressions in `keep-source' use "phase 0" expressions in `env'. Put
another way, require-for-syntax shifts the phase of a module by one.

Thus, relative to `keep-source', syntax in `env' has bindings for phase
1 and phase 2, but not phase 0.

In the above example, the error is that some syntax originating in
`env' has no phase 0 binding for `#%app' relative to `keeps-source'.

----------------------------------------

One solution is to fold everything into a single module;
`define-syntax-set' in "etc.ss" makes this reasonble, but not great.

Another solution is to abandon `syntax' in `env', have the caller of
`make-environment-syntax' provide a lexical-context object, and use
`datum->syntax-object' directly.

Neither solution is nice, and everyone who tries something complex runs
into this problem. Maybe the next iteration of the module system should
support something like `require-for-???' that imports into phase -1.

Matthew