[plt-scheme] dynamic-require with no "provided" argument
At Thu, 13 Nov 2008 13:08:06 +0000, Dave Gurnell wrote:
> I tried writing this:
>
> (dynamic-require (build-path "main.ss") (void))
>
> but nothing happened. I then tried refactoring main.ss and bundling
> the code into a "run-application" procedure:
>
> (let ([run-application (dynamic-require (build-path "main.ss")
> 'run-application)])
> (run-application))
>
> Doing this makes the application run twice. The docs say that dynamic-
> require "visits" and "instantiates" a module when a variable name is
> specified, but only "instantiates" the module if void is specified.
Actually, it only visits (i.e., runs the compile-time part of) a module
if `(void)' is given as the second argument. Supplying `(void)' doesn't
run the run-time part. That's probably the opposite of what you want.
> 1. Is there a way of visiting and instantiating a module without
> requiring a particular variable?
I think you probably want `(dynamic-require ... #f)', which
instantiates the module (i.e., runs the run-time part) but doesn't
bother to visit it (i.e., run the compile-time part).
In your `run-application' variant, did the module body already contain
a `(run-application)' call? That would explain why it ran twice: once
when instantiating the module, and again when the `dynamic-require'
result was called. Not calling `(run-application)' after
`dynamic-require' is essentially the same as supplying #f to
`dynamic-require'.
Matthew