Feedback Thread: DIP 1032--Function pointers and Delegate Parameters...--Community Review Round 1

Walter Bright newshound2 at digitalmars.com
Wed May 20 05:58:23 UTC 2020


On 4/3/2020 3:23 PM, Dukc wrote:
> I completely disagree with the notion that delegates with conventional syntax 
> should inherit the attributes of the function. First, the code breakage is going 
> to be high relative to the benefit.

That would only be true if the function never calls the delegate (i.e. it only 
stores the delegate elsewhere), which does happen but is not the usual use.


> Second, we are talking about adding a 
> special case to the language semantics, that is likely going to be hard to 
> understand and thus, to learn and remember.

On the contrary, it will likely not even be noticed. For example, it only makes 
sense that a pure function would need its delegate parameters to also be pure so 
it can call them. It's annoying to have to specify `pure` twice.


> If this proposal is changed to only propose this change to `lazy` parameters, it 
> might just be worth considering. `lazy` is already kind of "special" in it's 
> behaviour so I could see the special casing pshycologically easier to accept 
> there. But even there I'm sceptical.

The idea is to get rid of the special cases of lazy.


> What I'm saying next will be off the scope of the DIP, but I say it because of 
> the possibility that the DIP is unintentionally trying to solve the wrong 
> problem. The biggest problem with delegates in attributes is not that they don't 
> infer the attributes from the called function -vice versa! In the ideal world, 
> the called function would infer it's attributes from the delegate, not unlike 
> how `inout` function infers it's return value constness from constness of the 
> `inout` parameter.

Inferring function attributes from the delegate argument is impractical. For 
example, many delegates are trivial lambda functions, often inferred as pure. 
But the functions that call those delegates can rarely be pure. In effect, the 
function would have to be compilable with the *tightest* combination of 
attributes every time.


More information about the Digitalmars-d mailing list