Discussion Thread: DIP 1033--Implicit Conversion of Expressions to Delegates--Community Review Round 1
Patrick Schluter
Patrick.Schluter at bbox.fr
Thu Apr 23 11:13:34 UTC 2020
On Thursday, 23 April 2020 at 09:33:35 UTC, aliak wrote:
> On Wednesday, 22 April 2020 at 11:56:44 UTC, kinke wrote:
>> I don't think this is a good idea. One of the problems with
>> `lazy` IMO is that one needs good IDE support to somehow
>> highlight that the argument expression isn't evaluated before
>> the call, and might not be evaluated at all:
>>
>> // in some other module:
>> void foo(lazy int i) {}
>>
>> void main()
>> {
>> int i = 1;
>> foo(++i);
>> assert(i == 1); // what? not incremented above? ah yeah,
>> lazy and not evaluated at all by foo
>> }
>>
>> The proposal would extend that problem to regular delegate
>> params too. So I find the explicit version (`() => ++i`)
>> better to make that clear. I don't think the 'overhead' of
>> putting an additional `() =>` in front of the expression
>> justifies introducing the proposed implicit convertibility.
>
> I agree with this. Implicit conversion has always been argued
> against in D - why is it ok now? And this is not the good kind
> of implicit conversion where the user explicitly asks for it,
> but the bad kind where the language decides it should happen
> and the user doesn't know it can even happen.
>
> Thinking about it more now feels like the real rationale for
> the DIP is "in order to deprecate lazy, we need an alternative"
> ... ???
I always thought that lazy should also be marked at the call site
as it is a very different semantic on the caller and on the
callee. As it is now, it is true that the example above is
unfortunate and a real source of unpleasant surprizes.
void foo(lazy int i) {}
void main()
{
int i = 1;
foo(lazy ++i);
assert(i == 1); // No surprize here, the required annotation
tells it.
}
More information about the Digitalmars-d
mailing list