[plt-scheme] Evaluating code in namespace of calling module
At Thu, 17 Mar 2005 09:30:38 +0100, Erich Rast wrote:
> However, I'm still curious whether there generally is some way to
> evaluate code in one module as if it was evaluated in the calling
> module---something like a macro that expands in the namespace of the
> module it is used in, not in the module in which it is defined.
Like this?
(module m mzscheme
;; Defines `minus1' to use the `-' in the environment
;; of the macro use:
(define-syntax (minus1 stx)
(syntax-case stx ()
[(_ v) (with-syntax ([- (datum->syntax-object stx '-)])
#'(- v 1))]))
(provide minus1))
(module n mzscheme
(require m)
(define (f -)
(minus1 10))
(provide f))
(require n)
(f +) ; => 11
> (Of course, this would somewhat defeat the whole purpose of modules
> and might also raise security issues.)
For various reasons, you always have a trust a module if you use a
macro that it provides. But a macro-providing module doesn't have to
trust its users.
Matthew