www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Deprecate {} without () for function pointers and delegates

reply ABrightLight <example example.com> writes:
It's generally been agreed on in the past that {} without () in 
lambdas causes ambiguity with block statements.
```
void foo (void delegate () dg) {
   dg();
}

void main () {
   auto dg = {1.writeln;}; // Works.

   foo(dg); // function `foo` is not callable using argument types 
`(void function()  safe)` (This is not entirely related but I 
thought I'd point this out as something a bit odd)

   {1.writeln;}(); // Error
}
```
These are the simpler cases where it could be a problem. But I 
recently thought of `lazy`, and how expression-statements are 
coerced to delegates under the hood, but what if you wanted to 
pass a block statement to a function that takes `lazy`?

Anyway, I'd rather not have to juggle these questions in my mind, 
and a simple solution would be to deprecate function literals 
that omit the parentheses for the parameter list. Having to type 
an extra 2 characters is well worth not having to think about the 
edge cases.

Thank you
Jun 12
next sibling parent reply Mindy (0xEAB) <desisma heidel.beer> writes:
On Friday, 12 June 2026 at 21:07:49 UTC, ABrightLight wrote:
 It's generally been agreed on in the past that {} without () in 
 lambdas causes ambiguity with block statements.
I would have posted this to `digitalmars.dip.ideas`.
Jun 12
parent reply ABRightLight <example example.com> writes:
On Friday, 12 June 2026 at 22:02:28 UTC, Mindy (0xEAB) wrote:
 On Friday, 12 June 2026 at 21:07:49 UTC, ABrightLight wrote:
 It's generally been agreed on in the past that {} without () 
 in lambdas causes ambiguity with block statements.
I would have posted this to `digitalmars.dip.ideas`.
I didn't think a small change like this would need to be a DIP. Should I double-post?
Jun 12
parent Mindy (0xEAB) <desisma heidel.beer> writes:
On Friday, 12 June 2026 at 22:35:31 UTC, ABRightLight wrote:
 I would have posted this to `digitalmars.dip.ideas`.
I didn't think a small change like this would need to be a DIP. Should I double-post?
If it gains no traction in here, why not?
Jun 12
prev sibling parent reply Dmitry Olshansky <dmitry.olsh gmail.com> writes:
On Friday, 12 June 2026 at 21:07:49 UTC, ABrightLight wrote:
 Anyway, I'd rather not have to juggle these questions in my 
 mind, and a simple solution would be to deprecate function 
 literals that omit the parentheses for the parameter list. 
 Having to type an extra 2 characters is well worth not having 
 to think about the edge cases.
For me in Photon that would be the difference between go({ block of code }); and go((){ block of code }); Gnarly syntax reminding of c++ lambdas. While currenly it looks almost as simple as Go lang.
 Thank you
Jun 15
parent Meta <jared771 gmail.com> writes:
On Monday, 15 June 2026 at 07:46:41 UTC, Dmitry Olshansky wrote:
 On Friday, 12 June 2026 at 21:07:49 UTC, ABrightLight wrote:
 Anyway, I'd rather not have to juggle these questions in my 
 mind, and a simple solution would be to deprecate function 
 literals that omit the parentheses for the parameter list. 
 Having to type an extra 2 characters is well worth not having 
 to think about the edge cases.
For me in Photon that would be the difference between go({ block of code }); and go((){ block of code }); Gnarly syntax reminding of c++ lambdas. While currenly it looks almost as simple as Go lang.
 Thank you
With UFCS, that can also be written as: go = { block of code }; go = (){ block of code }; Gross.
Jun 15