proposal: short => rewrite for function declarations

Jacob Carlborg doob at me.com
Fri Oct 9 17:30:54 UTC 2020


On 2020-10-09 16:44, Adam D. Ruppe wrote:
> After a brief chat yesterday, I slapped this together:
> 
> https://github.com/dlang/dmd/pull/11833
> 
> In short, in a function declaration, it rewrites `=> ...;` into `{ 
> return ...; }`
> 
> One benefit is shorter property accessors:
> 
>      private int _x = 34;
>      @property x() => _x;
>      @property x(int v) => _x = v;
> 
> But it also works basically anywhere
> 
>      bool isNull() => this is null;
>      auto identity(T)(T a) => a;
>      @property y() in(true) => _x; // contracts still work too
> 
> So it just extends the existing lambda shorthand to full declarations too.

Yes please.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list