digitalmars.D - Deprecate {} without () for function pointers and delegates
- ABrightLight (24/24) Jun 12 It's generally been agreed on in the past that {} without () in
- Mindy (0xEAB) (2/4) Jun 12 I would have posted this to `digitalmars.dip.ideas`.
- ABRightLight (3/7) Jun 12 I didn't think a small change like this would need to be a DIP.
- Mindy (0xEAB) (2/5) Jun 12 If it gains no traction in here, why not?
- Dmitry Olshansky (7/13) Jun 15 For me in Photon that would be the difference between
- Meta (5/19) Jun 15 With UFCS, that can also be written as:
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
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
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:I didn't think a small change like this would need to be a DIP. Should I double-post?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
On Friday, 12 June 2026 at 22:35:31 UTC, ABRightLight wrote:If it gains no traction in here, why not?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
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
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:With UFCS, that can also be written as: go = { block of code }; go = (){ block of code }; Gross.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









Mindy (0xEAB) <desisma heidel.beer> 