This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
Re: Environments
- From: Per Bothner <per at bothner dot com>
- To: Dean Ferreyra <dferreyra at igc dot org>
- Cc: kawa at sources dot redhat dot com
- Date: Tue, 17 May 2005 18:16:09 -0700
- Subject: Re: Environments
- References: <428A899D.3000905@igc.org>
[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/