Discussion Thread: DIP 1043--Shortened Method Syntax--Final Review

harakim harakim at gmail.com
Fri Jun 17 22:11:38 UTC 2022


On Wednesday, 15 June 2022 at 13:40:20 UTC, Paul Backus wrote:
> On Wednesday, 15 June 2022 at 09:35:37 UTC, bauss wrote:
>> I'm still under the belief that it shouldn't just be 
>> `AssignExpression`, because you should be able to use it to 
>> call another function that has no return type.
>>
>> Ex.
>>
>> ```d
>> void a(int x, int y) { ... }
>>
>> void b(int x) => a(x, 100);
>> ```
>
> This already works--both for the new syntax, and for the 
> existing arrow-lambda syntax, and even for functions with an 
> explicit `return` statement:
>
> ```d
> void a(int x, int y) { /* ... */ }
> void b(int x) => a(x, 100);
> void function(int) c = x => a(x, 100);
> void d(int x) { return a(x, 100); }
> ```
>
> There is no need to specify this in the DIP because it is 
> already documented in the language spec, under the description 
> of `return` statements:
>
>> An Expression of type void is allowed if the function 
>> specifies a void return type. The Expression will be 
>> evaluated, but nothing will be returned.
>
> https://dlang.org/spec/statement.html#return-statement

Oh wow! Doing if () { writeln(); return; } has been a pet peeve 
of mine almost since I started programming. I never knew you 
could do if() return writeln() in D. That made my day. Thanks!


More information about the Digitalmars-d mailing list