UFCS doubt

2021-07-08 Thread Antonio via Digitalmars-d-learn
In this example (extracted from https://digitalmars.com/articles/b68.html), this works: ``` class C { int a; int foo(int i) { return i + a; } } auto mfp = (C self, int i)=>self.foo(i); void main(){ auto c = new C; assert( c.mfp(20)==20); } ``` but this fails ``` class C { int a; i

Re: UFCS doubt

2021-07-08 Thread Adam Ruppe via Digitalmars-d-learn
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 only works with functions defined at top level, not nested inside other functions. That's just how it is

Re: UFCS doubt

2021-07-08 Thread Dennis via Digitalmars-d-learn
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 fo

Re: UFCS doubt

2021-07-08 Thread jfondren via Digitalmars-d-learn
On Thursday, 8 July 2021 at 22:24:26 UTC, Antonio wrote: onlineapp.d(9): Error: no property `mfp` for type `onlineapp.C` I supossed that ```mfp(c,20)``` and ```c.mfp(20)``` should be equivalent because UFCS in second example, but it is not... why? https://dlang.org/spec/function.html#pseudo-

Re: UFCS doubt

2021-07-08 Thread Antonio via Digitalmars-d-learn
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

Re: UFCS doubt

2021-07-08 Thread Dennis via Digitalmars-d-learn
On Thursday, 8 July 2021 at 23:31:57 UTC, Antonio wrote: "It works as described in the manual, not as expected" (from MySQL haters club :-p) . Yeah, 50/285 people answering the question "What language features do you miss?" chose "UFCS for local symbols" in the [State of D survey (2018)](htt