Here's my proposal:

* Basics:

Parrot uses nested hashes for namespaces (like perl does).

The high-level language splits namespace strings using whatever
its separator is ('::', '.' etc) to generate an array of strings
for the namespace lookup.


* Relative roots:

Namespace lookup starts from a 'root' namespace (think root directory).
Here the P2 argument holds the root namespace to start the lookup from:

  find_global P1, P2, ['global', 'namespace', 'hierarchy'], "thingname"

If it's null then the interpreters default root namespace is used.

This scheme allows chroot() style shifting of the effective root.
(It's a key part of how the perl Safe module "works", for example.)


* Per-language root:

Each HLL could use a 'root' that's one level down from the true root.
Using a directory tree for illustration:

 /perl/Carp/carp          perl sees "Carp" at top level
 /java/java/lang/...      java sees "java" at top level


* Backlinks:

 /perl/main -.            "main" points back to "perls own root"
      ^------'            (so "$main::main::main::foo" works as it should)

 /perl/parrot -.          "parrot" points back to true root
 ^-------------'


* Accessing namespace of other languages:

Given the above, accessing the namespace of other languages is as simple as:

 /perl/parrot/java/java/lang/String/...

eg "$parrot::java::java::lang::String::CASE_INSENSITIVE_ORDER" for perl
and "parrot.perl.Carp.carp" for Java (perhaps, I don't claim to know any Java)


* Summary:

  - Nested hashes allow chroot() style shifting of the root.
  - That requires the 'effective root' to be passed to find_global.
  - Each HLL could have it's own 'root' to avoid name clashes.
  - Backlinks can be used to provide access to other HLL namespaces.
  - This combination of unification (all in one tree) and isolation
    (each HLL has a separate root) offers the best of all worlds.

Tim.

Reply via email to