the point of selective importing

Rioshin an'Harthen rharth75 at hotmail.com
Tue Jul 11 04:12:59 PDT 2006


"Rioshin an'Harthen" <rharth75 at hotmail.com> wrote:

Here I am, replying to my own post... :)

> I would prefer the syntax to be something akin to
>
> alias import module.with.a.long.name MWLN;
>
> which would be exactly like
>
> static import module.with.a.long.name;
> alias module.with.a.long.name MWLN;

I thought about it a little more, and came up with the following:

import module.name; - current import
static import module.name; - require FQN import
import module.name alias MN; - current import with automatic alias
static import module.name alias MN; - require FQN import with automatic 
alias

Basically thus:

The import statement imports the module, and enables the use of functions, 
classes, etc. of the module using just the name of the function, class, 
etc., or through a fully qualified name.

    import module.name; // contains function foo
    foo();    // legal
    module.name.foo();    // legal
    MN.foo();    // illegal

The static import statement is like the import statement, but requires the 
use of the fully qualified name to access functions, classes, etc.

    static import module.name;
    foo();    // illegal
    module.name.foo();    // legal
    MN.foo();    // illegal

The import ... alias statement is like the import statement, but adds the 
alias as an optional method of calling the functions, classes, etc.

    import module.name alias MN;
    foo();    // legal
    module.name.foo();    // legal
    MN.foo();    // legal

The static import ... alias statement is like the static import statement, 
but adds the alias as an optional method of calling the functions, classes, 
etc.

    static import module.name alias MN;
    foo();    // illegal
    module.name.foo();    // legal
    MN.foo();    // legal





More information about the Digitalmars-d mailing list