On Fri, Feb 13, 2009 at 09:44:12AM -0800, Jon Lang wrote:
: TSa wrote:
: > Does that imply that packages behave like C++ namespaces? That is
: > a package can be inserted into several times:
: >
: > package A
: > {
: > class Foo {...}
: > }
: > # later elsewhere
: > package A
: > {
: > class Bar {...}
: > }
: >
: > I would think that this is just different syntax to the proposed
: > form
: >
: > class A::Foo {...}
: > class A::Bar {...}
:
: Well, we _do_ have a mechanism in place for adding to an existing
: class (e.g., "class Foo is also { ... }"), and classes are a special
: case of modules; so I don't see why you shouldn't be able to do
: likewise with modules and even packages. That said, I'd be inclined
: to suggest that if this is to be allowed at all, it should be done
: using the same mechanism that's used for classes - that is, an "is
: also" trait.
These are actually package traits, not class traits, so your reasoning
is backwards, with the result that your wish is already granted. :)
However, it's possible we'll throw out "is also" and "is instead"
in favor of "multi" and "only", so it'd be:
multi package A {
class Foo {...}
}
multi package A {
class Bar {...}
}
to explicitly allow extended declarations. Modifying a package:
package A { # presumed "only"
class Foo {...}
}
...
multi package A {
class Bar {...}
}
would result in an error. In that case, the pragma
use MONKEY_PATCHING;
serves to suppress the redefinition error. It would also allow:
package A { # presumed "only"
class Foo {...}
}
...
only package A {
class Bar {...}
}
to do what "is instead" now does.
Apart from the parsimony of reusing an existing concept, the advantage
of doing it with "multi/only" is that the parser knows the multiness
at the point it sees the name, which is when it wants to stick A into
the symbol table. Whereas "is also" has to operate retroactively on
the name.
This also lets us mark a package as explicitly monkeyable by design,
in which case there's no need for a MONKEY_PATCHING declaration.
That being said, the CORE packages will not be marked multi. :)
Larry