Quick comparison of two Namespaces proposals

Michael van der Gulik mikevdg at gmail.com
Thu Sep 20 22:36:31 UTC 2007


On 9/20/07, Göran Krampe <goran at krampe.se> wrote:
>
> Hi Michael!
>
> >> If I understand you correctly (there are lots of assumptions here that
> I
> >> am not totally getting) - you are saying:
> >>
> >> - Package IS a Namespace.
> >> - Two packages CAN define names in the same namespace.
> >>
> >> I may be daft but I don't get it. So P1 "contains" N1 and so does P2?
> >> And
> >> a package IS a Namespace? So N1 can appear in multiple places in your
> >> hierarchy, is that what you mean?
> >>
> >
> > Well... kind of. I'll explain it in code:
> >
> > Package is a subclass of Namespace; Namespace is a subclass of
> Dictionary.
> >
> > p1 := Package new.
> > n1 := Namespace new name: #Namespace1.
> > p1 at: #Namespace1 put: n1. " should be p1 addNamespace: n1. "
> > n1 at: #X put: X.
> >
> > p2 := Package new.
> > n2 := Namespace new name: #Namespace1.
> > p1 at: #Namespace1 put: n2.
> > n2 at: #Y put: Y.
> >
> > Now, if you add both p1 and p2 to your local import list, you can refer
> to
> > Namespace1.X and Namespace1.Y.
> >
> > Does this answer your question?
>
> Ehm, well. :) It looks like a Package can contain any namespaces (like for
> example one that you already have with the same name in another package)
> and that the complete "tree" of the namespaces is the merged tree of all
> packages in your image? But then I have a hard time seeing that a Package
> ISA Namespace (subclass). Or perhaps the Namespace tree is in fact not a
> tree at all.
>
> And even if I am wrong... this feels complicated to me.



Yea, it's pretty complicated. I spent ages contriving up the design, but the
results are pretty spectacular and allow for some pretty nifty tricks.

I've edited http://gulik.pbwiki.com/Namespaces. Let me know if this is
easier to understand.

Packages sub-class from Namespaces so that they can contain Namespaces in
the same way that Namespaces contain other Namespaces. It also means they
can be validly added to import lists.

My namespaces are not all merged together, because the compiler does not
search every package/namespace instance in the image. The compiler /only/
searches a method's local Namespace instance, and then it searches that
local Namespace's import list. It does not search anywhere else. If the name
is not found in the local Namespace instance or in the import list, the code
will not compile. To make use of a name, you need to add the namespace
object containing that name to the local namespace's import list.

Gulik.



-- 
http://people.squeakfoundation.org/person/mikevdg
http://gulik.pbwiki.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20070921/93f941d3/attachment.htm


More information about the Squeak-dev mailing list