On Thursday, 8 July 2021 at 22:31:49 UTC, Dennis wrote:
On Thursday, 8 July 2021 at 22:24:26 UTC, Antonio wrote:
I supossed that ```mfp(c,20)``` and ```c.mfp(20)``` should be equivalent because UFCS in second example, but it is not... why?

UFCS does not work for nested functions.

Functions declared in a local scope are not found when searching for a matching UFCS function.
...
Rationale: Local function symbols are not considered by UFCS to avoid unexpected name conflicts. See below problematic examples.

https://dlang.org/spec/function.html#pseudo-member

Thanks.

I read the example and the assumption of "name conflict" does not seem to be justified (from my point of view)

i.e. Without dot notation, this example must fail
```
int front(int[] arr) { return arr[0]; }
void main()
{
    int[] a =[1,2,3];
    auto front = 1;       // front is now a variable
    auto y = front(a);   // Error, front is not a function
}
```
Changing to y = a.front() should not change the behavior (it is only a notation change )... but it does!!!
```
int front(int[] arr) { return arr[0]; }
void main()
{
    int[] a =[1,2,3];
    auto front = 1;       // front is now a variable
    auto y = a.front()     // NO ERROR!!!
}
```

"It works as described in the manual, not as expected" (from MySQL haters club :-p) .

Reply via email to