https://issues.dlang.org/show_bug.cgi?id=7176
Dlang Bot <dlang-bot@dlang.rocks> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |pull --- Comment #21 from Dlang Bot <dlang-bot@dlang.rocks> --- @adamdruppe updated dlang/dmd pull request #11833 "Implement shortened methods with => syntax" fixing this issue: - Fix issue 7176: Implement shortened methods with => syntax For function literals, D offers a short syntax: `x => y`, which expands to `function (x) { return y; }`. However, for normal function definitions, there was no such shortening. For various applications, there can be more syntax than meaning, such as property accessors. This commit changes that by expanding the same `=>` syntax we already have to work in declarations as well. It expands to the same thing: `int foo() => x;` is simply `int foo() { return x; }`; this is just shortened syntax. Combined with existing rules like auto returns, a property getter can be be as simple as `@property x() => x_;` or a range-based pipeline may appear like `auto common_operation() => this[].sort.uniq;` giving D's existing functional strengths more syntax sugar. C# has demonstrated the utility of such shortened methods since its version 7. However, while C# allows it for constructors as well, this commit will parse it but fail in semantic because you cannot return a value from a constructor. I am not convinced it is worth special-casing the simple "=> y ALWAYS means "{ return y; }" rule for this case and thus left it alone. https://github.com/dlang/dmd/pull/11833 --