[plt-scheme] can macros expand into (require (file ...)) ?
At Thu, 7 Aug 2003 11:55:26 -0400, "Felix Klock's PLT scheme proxy" wrote:
> However, now that I have finished developing the individual modules
> (and the units within), I seem to be lacking the provided variables
> from the modules that have been loaded via my macro-ized require
> statement.
When `require' is introduced by a macro, it acts something like a
`define' that is introduced by a macro. In the case of `define', the
binding scope is sensitive to content of the defined identifier. In the
case of `require', the binding scope is sensitive to the context of the
module reference; in the case of a symbolic module name, the references
is the name, etc.
For non-file requires, you have
(define-syntax require/noisy
(lambda (stx)
(syntax-case stx ()
[(require/noisy MOD)
(let ((sym (syntax-object->datum #'MOD)))
#`(begin (display (quote #,sym)) (newline)
(require #,(datum->syntax-object #'MOD sym))))])))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
where you've gone out of your way to give the required name the same
context as the original MOD. That's why it works. (Actually, I'm not
sure why you don't just use #'MOD, but no matter.)
In the file case, though:
(define-syntax require-file/noisy
(lambda (stx)
(syntax-case stx ()
[(require/noisy SYM)
(let ((str (string-append "~/Dev/scheme/code/test/"
(symbol->string (syntax-object->datum #'SYM)))))
(display str)
(newline)
#`(require (file #,str)))])))
the `(file ...)' reference has a context taht says it was introduced by
a macro, so it binds only references also introduced by the same macro
(and there are none).
You need to give the `(file #,str)' the context of the SYM:
#`(require #,(datum->syntax-object #'SYM `(file ,str)))
Matthew