On Fri, Dec 20, 2013 at 02:20:12PM -0500, Michel Fortin wrote: > On 2013-12-20 17:27:55 +0000, Andrei Alexandrescu > <seewebsiteforem...@erdani.org> 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. [...]
Using captaindet's idea of lazy imports, we could solve this problem: // Tell compiler that 'std.range' is a module, but don't import // it just yet. lazy import std.range; void func() { // Since the compiler already knows that 'std.range' is // a module, it knows to now import std.range and look // up 'InputRange.front' in it. auto x = std.range.InputRange.front; } T -- EMACS = Extremely Massive And Cumbersome System