DIP16: Transparently substitute module with package

Ary Manzana ary at esperanto.org.ar
Thu Apr 5 20:18:07 PDT 2012


On 4/5/12 10:55 PM, Steven Schveighoffer wrote:
> On Fri, 30 Mar 2012 10:46:19 -0400, Andrei Alexandrescu
> <SeeWebsiteForEmail at erdani.org> wrote:
>
>> 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!
>
> BTW, this case makes the part of DIP16 which wants to shortcut fully
> qualified names invalid, or at least costly (I posted this code in
> another part of the thread, but I thought I'd bring it up higher).
>
> The following is valid code today:
>
> a/b.d:
>
> module a.b;
>
> void foo() {}
> struct b
> {
> static void foo() {}
> }
>
> main.d:
> import a.b;
>
> void main()
> {
> a.b.foo();
> }
>
> If DIP16 were to be implemented, this becomes ambiguous. Is a.b.foo()
> the module function foo() from a.b, or is it a shortcut for a.b.b.foo()?

It's a shortcut to the module function foo().

If I replace main.d with:

void main() {
   foo();
}

Is foo() the module function foo() from a.b, or is it a shortcut for 
a.b.b.foo()? Here you have no doubts. What your mind does it: find a top 
level symbol "foo" in all imported modules. If you find more than one, 
error.

You must apply the same logic for "a.b.foo()". First you search "foo" in 
the "a.b" symbol. Here you find it: it's the top level function "foo" in 
"a.b". Then you stop searching.

However, if you can't find it in the module "a.b", you search a top 
level symbol "foo" in all modules that are in package "a.b". That's it. 
You don't search "foo" in every possible nesting: just module nesting.

>
> The main issue is, because you can shortcut the FQN, and a chain of
> identifiers can have repeated identifiers in them, ambiguity is possible.

As I said before, it's not a shortcut of the FQN: it's just a shortcut 
for the module name.


More information about the Digitalmars-d mailing list