fileVal Tradeoffs

There are two variations on fileVal.

The first presumes that the environments (namespaces) returned by scheme-report-environment are mutable, which is not required by the R5RS standard. An advantage of this fileVal is that the user and the resulting modules can not interfere with each other via a shared top level namespace. Vandalism such as (set! car 0) or (define cdr car) impacts only the guilty module.

The second creates no new environments and evaluates the text of the modules in the caller’s environment. This means that:

So far the second version has worked on each of the Schemes that I have tried it in on.

It is easy to create another fileVal that provides an environment that lacks the file primitives so as to keep untrusted modules from writing your file system. In that case you could pass as a parameter to the yielded function what-ever weakened primitives you wished.

(let ((ns (scheme-report-environment 5)))
   (eval '(define v 3) ns) (eval 'v ns))
should yield 3 if scheme-report-environment makes namespaces that can be expanded to include new names. If this fails then the first version of fileVal will fail.


(eval 3) ; => 3
fails then the second version will fail.

Just now after (use numbers) the two expressions:

(eval '(- 3 1) (scheme-report-environment 5)) ; => 2
((eval '- (scheme-report-environment 5)) 4 2) ; => 2
both fail in Chicken Scheme after the numbers package has been added and this makes both versions of fileVal fail.