On Friday, July 15, 2016 at 2:22:50 PM UTC+10, Jack Firth wrote: > I've got a macro that extends function definition by letting the user rebind > some identifiers with different values, which are then only available in a > certain context. For the sake of simplicity suppose it looks like this: > > (define/foo (func v ...) > #:bind [helper1 expr] > #:bind [helper2 other-expr] > (helper1 v ...) > (helper2 v ...)) > > I would like helper1 and helper2 to have their normal meaning unless I'm > inside a special `with-foo` form like so: > > (helper1 'a) ; normal behavior > > (with-foo func > ; in here, helper1 and helper2 are bound to expr and other-expr instead > (helper1 'a)) > > 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)) > > My reasoning is that by letting "func" double as a submodule identifier, I > can easily bring all the specially-bound identifiers associated with func > into scope, and by putting that submodule in a "foo" submodule I can hide the > existence of the foo submodule so only `with-foo` knows how to require the > correct "func" module. 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? -- 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 [email protected]. For more options, visit https://groups.google.com/d/optout.

