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

From: Don Blaheta (dblaheta at knox.edu)
Date: Mon Jan 19 02:22:09 EST 2009

Quoth Eli Barzilay:
> See also the reply I sent last evening describing how the sandbox
> library can be used for such things.  (Given that you already have a
> bunch of files and only want to script checking them, the sandbox
> library is what you really need, not the handin server.)

Yes, this is almost exactly what I was looking for (and for those
reading this via archive, the relevant post is in the thread "module
access from test cases file", partially quoted below).  I did have a
problem with the suggested incantation:

>  (require scheme/sandbox)
>  (define e (make-module-evaluator (string->path "...your file...")))
>  (e '...some-expression...)

when I did this, I got some errors from open-input-file claiming that it
lacked read permission (though the file was in the current directory and
readable); reading the doc for make-module-evaluator suggested that it
could take a port instead, so I tried

  (define e (make-module-evaluator (open-input-file (string->path "...your file..."))))

explicitly and this worked; I can now evaluate expressions in the
context of my students' definitions.  I'm still not sure why the first
version failed, though.


Now I'm on to actually writing the test cases.  Is there any way to
force a local on the evaluator?  That is, if I do

  (e '(define 'foo 3))

then this definition is permanent, and I'm not seeing a way to roll this
back short of making a new evaluator.  Is there a way?  (On reflection,
I don't really need this for the test cases I'll be doing, but I'm still
curious if it can be done.)


Relatedly, since the evaluator is now "in" one of the HtDP languages, I
don't have access to e.g. namespace-defined?, and the student code can
in any case crash or not work, and this appears to take down the whole
program, sandboxing notwithstanding.  For instance, if I

  (e '(/ 1 0))
  (printf "Testing.~n")

the printf never executes.  Am I misunderstanding the role of the
sandbox here?  I think I can work around this the same way I used to,
with a with-handlers clause that catches exn:fail?, but I suppose I was
expecting that the sandbox would take care of some of that for me.


Finally, I tried poking around with the new HtDP-style test cases, per
Matthias's suggestion:

Quoth Matthias Felleisen:
> #lang scheme
> (require htdp/testing)
> 
> ...
> 
> (generate-report)
> ;; the end
> 
> is close enough.

This was somewhat helpful, although I can't find any documentation on
it.  I did find a post from Kathy Gray from last September that
mentioned that htdp/testing was deprecated, apparently in favour of
test-engine/scheme-tests, which also seems to work; but I can't find any
docs on that either....  It looks like it won't be quite what I want,
because check-expect seems to need to be at the top-level, but I'm not
sure if there's a workaround.

-- 
-=-Don Blaheta-=-dblaheta at knox.edu-=-=-<http://faculty.knox.edu/dblaheta/>-=-
"I used to think that the brain was the most wonderful organ in my
body.  Then I realized who was telling me this."	--Emo Phillips


Posted on the users mailing list.