On Sun, Nov 10, 2019 at 6:45 AM Christopher Lemmer Webber <
cweb...@dustycloud.org> wrote:
>
> It sounds like what I want is the case of the export.

I'll run with this.

> I guess a question remaining then is: if I'm doing this kind of dynamic
> import of the module, is there a way to require from it (especially if
> it isn't assigned to a "filename" on disk?).

Try `local-require` inside a `let` or `let-values` body.

> It appears there must be;
> when I look at `build-program` in sandbox.rkt it also looks like it's
> wrapping things in a module structure... but I don't see how it then
> exports from that module or how the code evaluating it imports its
> export.  Or does it actually do so via an effect?  I see there are some
> channels involved (input-ch / result-ch) so maybe it's passing back the
> result through there, but I am having trouble figuring out how.

Apologies for stating the obvious, but to get a value out of a module, we
`provide` it:

In foo/main.rkt:

```
(define-syntax-rule (foo-module-begin form ... final-form)
  (#%module-begin (provide the-foo) form ... (define the-foo final-form)))
```

Then we can produce and consume foo-based modules like this:

```
(module bar-mod foo (define bar 1) (+ bar 2))

(define my-bar (let () (local-require 'bar-mod) the-foo))
```

Coincidentally, I've got notes on using this technique to wedge a `#lang`
into the body of a defining form; a `define-foo` form, for example, that
treats its contents as if it were read from a file that starts with `#lang
foo`. It's part of an upcoming blog series on functional meta-programming
with Racket. I've got a few graphics packages in the pipe to celebrate the
Racket Game Jam, so it might be a few weeks before this article hits the
blog, but I'm happy to continue discussing and share my notes any time.

Eric

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAORuSUxdhH5gipo9sQ9uaD%3D_KCKBopZbQ1xPZAXyDWFdVae_yw%40mail.gmail.com.

Reply via email to