On 2013-12-20 17:27:55 +0000, Andrei Alexandrescu <[email protected]> said:

I had this idea fot a while, and Walter is favorable of it as well - extend "import" for one-shot use. With that feature the example would become:

     void topN(alias less = "a < b",
             SwapStrategy ss = SwapStrategy.unstable,
             Range, RandomGen)(Range r, size_t nth, ref RandomGen rng)
         if (isRandomAccessRange!(Range) && hasLength!Range
             && import.std.random.isUniformRNG!RandomGen)
     { ... }

In this case "import" would syntactically be placed at the beginning of a qualified name, meaning "import this module lazily and look up the symbol in it".

This would simplify quite a lot of two-liners into one-liners in other places, too.

How do you solve the problem that in D you can't tell the module name from a fully qualified names? For instance:

        import.std.something.somethingelse.anotherthing = 1;

Is the module std? std.something? std.something.somethingelse? It could be any of these answers.

        module std.something;
        struct somethingelse { static int anotherthing = 0; }

or

        module std.something.somethingelse;
        int anotherthing = 0;


--
Michel Fortin
[email protected]
http://michelf.ca

Reply via email to