DIP16: Transparently substitute module with package

Andrej Mitrovic andrej.mitrovich at gmail.com
Fri Mar 30 11:06:57 PDT 2012


On 3/30/12, Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org> wrote:
> Destroy!

"That means a program that imports std.algorithm may use "std.sort"
for the symbol "std.algorithm.sort"."

That's quite interesting. Would that also mean that you could do:
import std.algorithm;  // has indexOf
import std.string;  // has indexOf
void main() {
    string.indexOf("foo", "foo"); -> std.string.indexOf
}

That would ease usage of Phobos a little bit. OTOH 'string' already is
a keyword and things might get hairy..

Still this is one of the few proposals I like. My only caveat is the
comment: "except the file is not allowed to use the "module"
declaration.". Wouldn't it be better if we explicitly declared a
module as a package instead? In foo\bar\package.d:
package foo.bar;

Since the "module" declaration must be on the first line (or second
line after shebang), you could special-case DMD to allow the package
keyword to be used here. I know D likes to abuse a keyword for
multiple things (hello Mr. Static!), but I think we could live with
it.


More information about the Digitalmars-d mailing list