This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Environments


[I took the liberty of cc'ing my reply to the list.]

Dean Ferreyra wrote:
We use this idiom in our code base:

        Scheme.registerEnvironment();
        Scheme scm = Scheme.getInstance();

        scm.eval("(define (dean) 1)");
        Environment env = scm.getEnvironment();
        Object val = env.get("dean");

but this no longer works; for me val comes back as null where I used to get back the ModuleMethod. But, change the environment line to:

Environment env = Environment.getCurrent();

and it works. Is this expected? What's the difference between Scheme.getInstance().getEnvironment() and Environment.getCurrent()?

Unfortunately, Scheme.getInstance().getEnvironment() returns the Scheme-specific environment that only contains the builtin definitions. It corresponds to (scheme-report-environment 5) - except that it also includes kawa extensions.

On the other hand, Environment.getCurrent() gets the current thread's
user environment, corresponding to (interaction-environment).

The unfortunate part is that the Kawa manual recommends:
  Environment.setCurrent(new Scheme().getEnvironment());
which is now wrong.  I should change Scheme.getEnvironment()
to be a (deprecated) synonynm for Environment.getCurrent(),
in which case the Environment.setCurrent becomes a harmless
no-op.  It does means I have to fix the places that make
use of the current Scheme.getEnvironment(), which don't seem
to be very many.

The manual also recommends 'new Scheme()' which is also wrong,
but should be harmless.
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]