[racket] Lifting submodules
> I want to write a macro which generates submodules and then possibly
> requires them. This is so that can easily use another language (TR)
> for the expression.
>
> If all uses of the macro are at the top-level/module-level this is
> easy and I can expand out to something like:
> (begin
> (module new-mod typed/racket <expr and provides>)
> (require 'new-mod)
> <use exports>)
Easy... except I can't get even that to work. Even used at the top-level.
I tried because there's a StackOverflow question about this:
http://stackoverflow.com/questions/18852921/generating-require-clauses-with-racket-macros
I've been trying to answer it, but having one of those humbling
experiences where I wonder how much I've really learned about macros,
after all. I distilled it to just:
#lang racket
(define-syntax (define-modularize stx)
(syntax-case stx ()
([_ thing-name mod-name]
#'(begin
(module mod-name racket
(define thing-name #t)
(provide thing-name))
(require 'mod-name)))))
(define-modularize foo foo-mod)
;; (require 'foo-mod)
foo ;; => foo: unbound identifier in module
Only if the previous line with the require is uncommented, does it
work. IOW the module and thing define/provide seem just fine, it's the
require that is not working. Why?
I've thought about it, used the stepper in DrRacket, tried everything
I can think of -- but can't get it to work.