[plt-scheme] Exporting from an already-written module?

From: Don Blaheta (dblaheta at knox.edu)
Date: Mon Jan 19 17:46:59 EST 2009

Quoth Eli Barzilay:
> On Jan 19, Don Blaheta wrote:
> > Quoth Eli Barzilay:
> (The problem is not with the file being readable to you,
> it's about the sandboxed environment being very limited in what it can
> access. ...

Yes, I thought it might be something like that.  I certainly understand
why the *sandboxed* code shouldn't be able to access files like that. :)

> Then you can bind your own `x' to the twice the value of the student's
> `foo':
> 
>   (define x (* 2 (e 'foo)))
> 
> and use this value with the student's `add' function:
> 
>   (e `(add foo ,x))

The (e 'foo) trick I had figured out, and I'm definitely coming around to
understanding its usefulness... quasiquote makes it even better ;)

> Using the sandbox environment is very convenient, because it provides
> a clear separation between what happens inside the student code and in
> your testing code.

Yes.

> In any case, the solution for this is a new `call-in-sandbox-context'
> function which will run an arbitrary thunk (*your* code) inside the
> sandbox environment.  For example, to check if a name is defined using
> that function, you can do this:
> 
>   (require mzlib/etc)
>   (call-in-sandbox-context e (lambda () (namespace-defined? 'foo)))

Ooh, neat.  My thunked code runs with its own stuff in the closure, but 
the "current" namespace when its running is the students' definitions?
I think I get it; I need to play with namespaces more.

> Therefore, uses of sandboxes almost always need to catch all
> exceptions from the sandbox, and be aware of multiple values.  But you
> do get a lot of help in that *all* errors are just exceptions.

A HA!  That last was precisely the sentence that made all sorts of stuff
click for me.  

> I didn't do that since it seems like a trivial thing to setup.  (By
> the way, note that there can be anything in the second form, since you
> can call `raise' directly on any value, not just an exception.)

Yeah, now that I understand what's going on here, I can write or adapt my
existing test suite stuff.  (Although, I should probably at least look
at the handin server---guess it's time to start grabbing from the SVN
repository. :)

-- 
-=-Don Blaheta-=-dblaheta at knox.edu-=-=-<http://faculty.knox.edu/dblaheta/>-=-
"Something's been sticking in my craw.  No surprise there; I was born
with an unusually narrow craw."			--Stephen Colbert


Posted on the users mailing list.