[racket] nested environments

From: synx (plt at synx.us.to)
Date: Sun Jun 13 15:30:22 EDT 2010

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I am trying to represent a situation where there are a number of
"environments" that each contain a number of named procedures. These
environments can be nested, in that there is a base environment and
other environments that add to or replace from its list of named
procedures.

I realize I'm probably using entirely the wrong terms for all this.
Anyone who can direct me to the correct ones would be most appreciated.
I think "environment" might be best represented by a "module" but
haven't quite figured out how to make it work.

So for instance in the following situation there are two branches in a
single sort of environment "tree"

A - defines a, b, c
B - defines b, d
C - defines c, f
D - defines e, f, g
E - defines e, d, g

A  A
B  C
D  E
x  x

I want to evaluate expression x in the context of both environment
hierarchies, where the first one uses the e, f, and g from D, the b and
d from B, and the a and c from A; and the second one uses the e, d, and
g from E, the c and f from C, and the a and b from A. x could be any
expression such as '(a (b (c (d (e (f (g))))))) that would be expected
to produce different results in the two environment hierarchies, though
the expression '(a) would produce the same result since it uses the same
procedure for 'a in environment A.

It's almost like I want D to be a module that requires B, which requires
A, and E to require C which requires A. Then I could use
namespace-require to attach modules D, then E to a namespace and
evaluate the expression within that. But I would like to add, modify and
remove identifiers and procedures, and I don't think you can do that
with a module. I could replace the entire module, but replacing module A
for instance would require me to also replace modules B, C, D and E with
modules that require the new A, and I'm not sure how to keep track of
all that. Modules specify the modules they require as an internal
syntax, so it's not like I can go (module-requires module) -> (listof
requires) or anything.

It's not like I have filesystem files and directories to rely on here.
It's more like environment id,name,s-expression, as gotten from some
sort of database, for each procedure. Putting all the procedures for an
environment in one file might seem nice, but then I would have to
recreate this dummy file every time one of my procedures changed, or a
new one was added, or an old one removed. That might also introduce
problems keeping it synchronized, or even race conditions.

I don't want to have to deal with a situation where there are 10
environments all depending on module A, so changing one procedure in
module A requires recreating module A and all 10 environments, as well
as manually keeping track of which module depends on whom. But I don't
know how to abstract that, or if there's a better way to do it, or if
it's already been done?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJMFTHOAAoJECC/cKf8E7UIsy8H/2dat7imLCdmjhk+kjvYmVf9
2YV2FPJkKByy+n7Nfvwbycy3mXNl4TZ43kBUccr26CZepmyo6F2sbzG8Q7WXERcl
xv6LmnZa0IPhUu6S4i1PM5DepwcwjGLhqWsEbj5xHEFpOvAFfUDeUUEJQxAmUy2V
Q2iKEnKw82Pgv1QHrSK/eSY8A7ivA/oq6fX0F430etgtnOD2WzFllJpMJNB1MF9v
P1FZFbzNXxcG/X5w/UT+99cR1s1ZpWWqF0TgnVjMKLCgh3CT81VysnG2H42DBX+u
dATiHpbOtu0JCU+2f4EBPkVdctNJQvl6SuLNXkvfVD8oOarv4Fd/SMqdYcWLgDE=
=yE+5
-----END PGP SIGNATURE-----


Posted on the users mailing list.