[plt-scheme] Trouble with namespace-require

From: Bertrand Petit (plt-s at phoe.frmug.org)
Date: Sat Apr 16 22:44:37 EDT 2005

	I need, for the purpose of configuring an application, to
evaluate a file containing user-supplied expressions. The user can
utilize common scheme expressions, dedicated procedures and syntaxes.
The later two are used for their side-effects. I wish to provide a
clean and separate evaluation environment so that the user can not
mangle other parts of the application (IE definitions from the module
that loads the configuration file). I thinks that's a case were
name-spaces are really handy. I'm using mzscheme version 299.102.

	Initially I though that I would only need to create a new
initial name-space, augment it with my definitions and syntaxes using
values and syntaxes taken from the configuration loader module.
NAMESPACE-SET-VARIABLE-VALUE! was able to be the trick to augment the
new name-space with my definitions but I found no mean to add already
defined syntaxes.

	Then I went another way. I created a dedicated module that
exports all the definitions and syntaxes usable in the user
environment. That module also exports protected identifiers so that
the application could collect the results of the side-effects applied
in the user environment. That almost did the trick. The two modules
are called config-core (the configuration loader) and config-env
(contains the definitions augmenting the user environment). config-env
is declared like this:

(module config-env mzscheme
	(require (lib "include.ss"))
	(include "config-env-src.scm")
	(provide foo
		 (protect bar)))

The file config-env-src.scm contains all the definitions. The
config-core module is similarly declared, it only exports the
READ-CONFIG procedure, its body is as follows.

(require "./config-env.scm")
(define read-config
  (lambda (filename)
    (let ((namespace (make-namespace 'initial)))
      (parameterize ((current-namespace namespace)
		     (current-code-inspector
		      (make-inspector (current-code-inspector))))
	(namespace-require "./config-env.scm")
	(load (simplify-path filename))))))

All goes well if the config-env module is attached to the new
name-space in the context of the code inspector in effect for the body
of the config-core module. If I create a new code inspector as it was
just shown, the NAMESPACE-REQUIRE procedure yields the following error
message that I can't understand: "compile: access from an uncertified
context to unexported variable from module: #%stxcase in:
ellipsis-count-error".

	All of this is fairly new to me as a I never explicitly
manipulated name-spaces before. This leads me to ask two questions:

    1. Does the method here described to provide independent but
       "peek-able" evaluation environments sounds same? If it is not
       same could you suggest a different method?

    2. What is the meaning of the quoted error message and how to
       circumvent it?

	Regards,
	Bertrand.

-- 
%!PS
297.6 420.9 translate 90 rotate 0 setgray gsave 0 1 1{pop 0 180 moveto 100
180 170 100 170 -10 curveto 180 -9 180 -9 190 -10 curveto 190 100 100 180
0 180 curveto fill 180 rotate}for grestore/Bookman-LightItalic findfont
240 scalefont setfont -151.536392 -63.7998886 moveto (bp)show showpage



Posted on the users mailing list.