I am trying to write in Racket a metalanguage of the mylang module, which accepts a second language into which the modified body passes, such that
(module foo mylang typed/racket body)
equivalent to:
(module foo typed/racket transformed-body)
where the typed/racket can be replaced with any other module language, of course.
I tried a simple version that left the body unchanged. It works fine on the command line , but when launched in DrRacket gives the following error:
/usr/share/racket/pkgs/typed-racket-lib/typed-racket/typecheck/tc-toplevel.rkt:479:30: require: namespace mismatch; reference to a module that is not available reference phase: 1 referenced module: "/usr/share/racket/pkgs/typed-racket-lib/typed-racket/env/env-req.rkt" referenced phase level: 0 in: add-mod!
Here is the whole code:
#lang racket (module mylang racket (provide (rename-out [-#%module-begin #%module-begin])) (require (for-syntax syntax/strip-context)) (define-syntax (-#%module-begin stx) (syntax-case stx () [(_ lng . rest) (let ([lng-sym (syntax-e #'lng)]) (namespace-require `(for-meta -1 ,lng-sym)) (with-syntax ([mb (namespace-symbol->identifier '#%module-begin)]) #`(mb . #,(replace-context #'mb #'rest))))]))) (module foo (submod ".." mylang) typed/racket/base (ann (+ 1) Number)) (require 'foo)
Requirements (i.e. solutions that I would prefer to avoid):
- Adding
(require (only-in typed/racket)) inside the mylang module does the job, but I'm interested in a general solution where mylang doesn't need to know about typed/racket in al (i.e. if someone adds a new language foo , then mylang should work with it out of the box). Also, I'm not interested in the tricks that declare a submodule, and then require and ref provide it, as it is done here , because it changes the path to the actual module (therefore main and test will lose their special behavior, for example).
It is also slower during compilation, since submodules get visited and / or instance more times (this can be seen from the entry (begin-for-syntax (displayln 'here)) and has a noticeable effect on large typed/racket programs.
Bonus points if arrows in DrRacket work for built-in modules provided by a delegated language, for example. have arrows from ann , + and Number to typed/racket/base in the above example.
racket require metalanguage
Georges Dupéron
source share