DIP16: Transparently substitute module with package
deadalnix
deadalnix at gmail.com
Sat Mar 31 12:40:15 PDT 2012
Le 30/03/2012 16:46, Andrei Alexandrescu a écrit :
> Starting a new thread from one in announce:
>
> http://prowiki.org/wiki4d/wiki.cgi?LanguageDevel/DIPs/DIP16
>
> Please comment, after which Walter will approve. Walter's approval means
> that he would approve a pull request implementing DIP16 (subject to
> regular correctness checks).
>
>
> Destroy!
>
> Andrei
OK, here is an alternative proposal, based on what has been said here,
and in other thread. I think it is a better alternative because it is
almost already working.
1/ you can defined both a.d (d source code) and a (folder) in the same
folder.
2/ import a; will always look for a.d . a folder. a existing isn't an error.
3/ import a.b will look for b.d in a folder. If a.d exists, it isn't an
error.
4/ The package a include what in a.d and everything defined in d files
in the folder a and its subfolders.
5/ What is publicly imported get automatically aliased in the importing
module. See example below if it is not clear :
a.d :
public import a.b;
b.d :
void foo() {}
automatic aliasing in a.d would look like :
public import a.b;
// Automaticaly added aliases :
alias b.foo foo;
And usage from third party code :
import a;
void main() {
foo(); // OK
a.foo(); // OK
a.b.foo(); // OK
}
And with static import :
static import a;
void main() {
foo(); // Error
a.foo(); // OK
a.b.foo(); // OK
}
More information about the Digitalmars-d
mailing list