lazy import, an alternative to DIP 1005
Jonathan Marler via Digitalmars-d
digitalmars-d at puremagic.com
Fri Sep 15 15:16:34 UTC 2017
On Friday, 15 September 2017 at 14:45:01 UTC, Jonathan Marler
wrote:
> ...
Wanted to add that I believe we could also make "selective
imports" lazy, either be default or possibly by adding a modifier
like "lazy" if non-lazy imports are still useful.
lazy import std.stdio : File;
lazy import std.range : isInputRange;
void process(File input) ;
struct Buffered(Range) if (isInputRange!Range)
{
...
}
It works because the semantic analyzer knows that the "File"
symbol is referring to something in module std.stdio, so it can
delay importing std.stdio until it needs to resolve the File
symbol.
If this was implemented, not sure if there is a benefit to
turning lazy imports on/off, if not, then we could just forgo the
new "lazy" modifier and just make all "qualified imports" lazy.
Note this can't work with normal imports because in that case you
need to import the module just to know what symbols it contains.
This idea only works with "static imports" and "selective
imports".
More information about the Digitalmars-d
mailing list