> On Jul 15, 2016, at 1:54 AM, Jack Firth <jackhfi...@gmail.com> wrote: > > On Thursday, July 14, 2016 at 10:28:07 PM UTC-7, mattap...@gmail.com wrote: >> On Friday, July 15, 2016 at 2:22:50 PM UTC+10, Jack Firth wrote:
>>> I'd also like `with-foo` to be the only way to access the versions of >>> helper1 and helper2 that have this alternate behavior. I'm attempting to do >>> this with some submodule hackery, essentially I'm expanding the above to >>> this: >>> >>> (define (func v ...) >>> (helper1 v ...) >>> (helper2 v ...)) >>> >>> (module foo racket/base >>> (module+ func >>> (define helper1 expr) >>> (define helper2 other-expr) >>> (provide (all-defined-out)))) >>> >>> (begin >>> (require (submod ".." foo func)) >>> (helper 1)) >>> But I'm hitting scope issues - I'm not sure hot to make the redefinitions >>> of func available in (body ...) in a (with-foo func body ...) use, naively >>> adding the require imports fails to bring them into scope. Various >>> combinations of using syntax/loc and datum->syntax on the require >>> statement, the require submod path, and/or the body are all failing to do >>> what I want. >>> >>> How can I achieve this? Is there a better way to try and do this? >> >> Although I'm not experienced enough to understand all that's going on in >> your design, I wanted to remind you of (require (for-syntax )) since you're >> using the required module in the macro? > > The macros don't use the defined modules themselves, the runtime expressions > wrapped by `with-foo` do. A runtime require is definitely what I'm looking > for. I've made some progress where `with-foo` is implemented basically like > this: > > (define-syntax-parser with-foo > [(_ foo-defined:id body ...) > #`(let () > (local-require > #,(syntax-local-introduce > #`(submod "." foo foo-defined))) > body ...)]) > > But when I attempt to use it, e.g. (with-foo func (helper1 ...)), I get the > error "helper1: identifier's binding is ambiguous in context" which I'm > guessing is because syntax-local-introduce is doing quite what I want with > scopes. Your definition of of `with-foo` works with this small example, so it looks like that `syntax-local-introduce` is doing the right thing. How are the other macros defined? How do things work within the body of the `func` function, for example? #lang racket (require syntax/parse/define) (define (helper1 v) 'normal-behavior) (define (helper2 v) 'normal-behavior) (helper1 'a) (helper2 'b) (module foo racket/base (module+ func (define (helper1 v) 'func-behavior) (define (helper2 v) 'func-behavior) (provide (all-defined-out)))) (define-syntax-parser with-foo [(_ foo-defined:id body ...) #`(let () (local-require #,(syntax-local-introduce #`(submod "." foo foo-defined))) body ...)]) (with-foo func (helper1 1)) Alex Knauth -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.