Mixin and imports

Steven Schveighoffer schveiguy at gmail.com
Mon Jun 8 16:02:02 UTC 2020


On 6/8/20 11:11 AM, jmh530 wrote:
> On Monday, 8 June 2020 at 14:27:26 UTC, data pulverizer wrote:
>> [snip]
>>
>> Out of curiosity what does the "." in front of `foo` mean? I've seen 
>> that in some D code on the compiler in GitHub and have no idea what it 
>> does. I tried Googling it to no avail. It doesn't have anything to do 
>> with UFCS does it?
>>
>> Thanks
> 
> ag0aep6g provided the link to it, but it's one of those things that has 
> been difficult for me to understand as well. I believe the original code 
> had `foo` in a template. So in that case it was necessary. I'm not sure 
> if it still is in my simplified version.

The dot operator simply specifies that the symbol you are looking for is 
defined at global scope, so it just changes the lookup rules.

Even though it makes the code clearer what foo you are looking at, it 
was not necessary -- removing the dot works.

In some cases it is necessary to use the . lookup rule, because you have 
another symbol that will be picked first.

For example:

int x;

template bar(string x)
{
    mixin("alias " ~ x ~ " = .x;");
}

-Steve


More information about the Digitalmars-d-learn mailing list