Discussion Thread: DIP 1033--Implicit Conversion of Expressions to Delegates--Final Review
Walter Bright
newshound2 at digitalmars.com
Sun Nov 22 09:16:11 UTC 2020
On 11/20/2020 12:18 AM, Manu wrote:
> Another question that comes to mind, where the dip shows:
>
> int delegate() dg = () {return 3; };
>
> becomes:
>
> int delegate() dg = ()=> 3;
>
> become simply:
>
> int delegate() dg =3;
>
>
> <https://github.com/dlang/DIPs/blob/8e56fc593ece5c74f18b8eb68c3f9dcedf2396a7/DIPs/DIP1033.md#prior-work>
>
> This isn't an example of passing a lazy argument to a function that receives a
> delegate; this demonstrates initialising a delegate variable declaration. That
> seems off-topic to me, but it raises the question, does this now work for
> delegates that receive parameters:
>
> int delegate(int x) dg = x + 10;
>
> ??
> Are the parameters in scope for the expression to the right of the `=`?
No. Initializers are semantically analyzed before the initialized, hence the
parameter x will be unknown. You'll have to declare it as:
int delegate(int) dg = (int x) { return x + 10; };
More information about the Digitalmars-d
mailing list