[Issue 7176] Lambda => syntax for function and methods too

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Feb 11 04:49:26 PST 2016


https://issues.dlang.org/show_bug.cgi?id=7176

--- Comment #20 from Nick Treleaven <ntrel-pub at mybtinternet.com> ---
Just noticed C# 6.0 has this syntax, they call it "Expression Body
Definitions":
https://msdn.microsoft.com/en-us/library/ms173114.aspx#Anchor_6

C# also has the same (x, y) => x == y lambda syntax as D. C# having this
feature indicates the syntax may be worth adding.

Regarding function syntax consistency, we now allow lambdas to be used with
alias:

alias square = x => x ^ 2;
auto square(T)(T x) => x ^ 2; // proposed
auto square(T)(T x) {return x ^ 2;}

The proposed function definition syntax would be more consistent with the alias
(and more flexible than alias).

The main point of this request IMO is to reduce brace nesting, braces and
brackets are visually noisy and make the programmer have to mentally match them
up.

--


More information about the Digitalmars-d-bugs mailing list