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

From: Eli Barzilay (eli at barzilay.org)
Date: Mon Jan 19 17:55:33 EST 2009

On Jan 19, Don Blaheta wrote:
> Quoth Eli Barzilay:
> 
> > 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?

Yes.


> I think I get it; I need to play with namespaces more.

As another example, you can grab the student's namespace with

  (call-in-sandbox-context e current-namespace)

but there are other things that are local to the sandboxed
environment.  (For example, it runs on a different thread, under a
different custodian, with a different eventspace, etc etc.)  The
summary is that the sandbox library deals with a bunch of fairly
low-level stuff that is needed to make it happen, but that you won't
want to learn to just run the code...


> > 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.

In that case it would be nice if you find a place to add it to the
documentation page so it's more obvious.


> > 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. :)

Well, the handin server is doing a bunch of other stuff too -- if all
you need is test student code, then the sandbox is enough for just
that.  Use the handin server when you want to automate homework
submission (and as a side bonus it can do some checking of student
code while it's being submitted.)

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.