Modules don't evaluate to values. They have effects and they have exported symbols. If you want to observe the evaluation of your language's module, you'll have to look at one of those two things. Both are used by existing Racket languages and infrastructure: `raco test` relies on test modules making effects on a global box that counts how many tests ran and failed. `scribble` relies on inspecting an export named `doc`. In either case, I think you want to make `#%module-begin` capture the last expression and expose its value via an effect or an export.
Jay -- Jay McCarthy Associate Professor @ CS @ UMass Lowell http://jeapostrophe.github.io Vincit qui se vincit. On Sat, Nov 9, 2019 at 9:54 AM Christopher Lemmer Webber <cweb...@dustycloud.org> wrote: > > (Caveat: I know the sandbox evaluator exists. I'm trying to understand > how to do this without it, to understand the evaluation machinery for > something.) > > Let's say I write "#lang foo". For whatever reason, I have programs > that are coming in from users that are not necessarily being saved > to a file on disk... they may be coming from a GUI, read over the > network, etc etc. The only important thing is that at the end of the > program, the last expression returns some value, and I want access to > that value. Simplest example, let's say we have the following program > > ``` > #lang foo > > (define bar 1) > > (+ bar 2) > ``` > > I'd like to read this in and evaluate it, so presumably I'd want to get > 3 returned. > > I've tried to figure out how to do this from trivial examples but I'm > not having success. I can see that I can read in a module: > > ``` > racket-sandbox.rkt> (parameterize ([read-accept-reader #t]) > (call-with-input-string "#lang racket/base > (+ 1 2)" > (lambda (ip) > (read-syntax 'foo ip)))) > #<syntax:foo::7 (module anonymous-module racket/base (#%module-begin (+ 1 > 2)))> > ``` > > Cool, ok. > > But when I pass this module-wrapped structure to eval, the result is void. > > What should I do? Help appreciated! > > -- > 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/8736exhzh8.fsf%40dustycloud.org. -- 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/CAJYbDak7zwYp8gCW2zA%2B3hNGLLqr3tjRks7bO47X0st94s0Hiw%40mail.gmail.com.