[Issue 3603] Allow selective import syntax to import several modules from a package

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jan 6 14:32:25 UTC 2019


--- Comment #5 from Nick Treleaven <nick at geany.org> ---
(In reply to John Hall from comment #4)
> import foo : bar, baz;
> how does the compiler know to import the functions or the modules?

It could work:
1. If foo is a file called foo.d, it's a module import with selective symbols.
2. If a directory foo/ exists as well, the compiler could show a warning.
3. If foo is not a file but a directory, it's a package import with selective

Although when searching multiple import paths given on the command-line it
could get confusing with conflicts.

> import foo :: bar, baz;

That is clearer syntax and simplifies the feature design, but it seems a bit
inconsistent with fully qualified symbols in code, which use
`package1.module1`, not `package1::module1` (the latter would arguably be
better for FQNs but I doubt it will be added now). `import package foo : bar,
baz;` syntax is another option, and is intuitive.

This Phobos file is a good example case for this feature:

In fact, I think a single package import with selective modules could also
support selectively importing a single symbol from each module (which is a
common case for library code):

import mod : sym1, sym2; // selective symbols from a single module
import package pack : mod1, mod2, mod3; // selective modules from a single
import package pack : mod1, mod2 : sym, mod3 : sym; // selective modules plus
optional single selective symbol per module

For multiple selective symbols per module, this is not possible with this
syntax, use a separate import statement per module. This is a better design IMO
than allowing arbitrary `{mod1, mod2 : {sym1, sym2}, mod3 : {sym1, sym2}}` code
because it forces better readability.

The grammar (ignoring renaming) would be something like:

  import ModuleIdentifier : SymbolImportList;
  import package PackageIdentifier : ModuleImportList;
  ModuleIdentifier : SymbolIdentifier
  ModuleIdentifier, ModuleImportList
  ModuleIdentifier : SymbolIdentifier, ModuleImportList


More information about the Digitalmars-d-bugs mailing list