Lambda syntax for methods and functions

Marco Leise Marco.Leise at gmx.de
Sat Dec 7 23:58:43 PST 2013


Am Sat, 07 Dec 2013 21:21:03 +0100
schrieb "Jesse Phillips" <Jesse.K.Phillips+D at gmail.com>:

> On Saturday, 7 December 2013 at 17:43:46 UTC, MattCoder wrote:
> > On Saturday, 7 December 2013 at 17:29:43 UTC, bearophile wrote:
> >> public Point Move(int dx, int dy) => new Point(X + dx, Y + dy);
> >>
> >> That means:
> >>
> >> public Point Move(int dx, int dy) { return new Point(X + dx, Y 
> >> + dy); }
> >
> > Maybe It's just me, but on the example above I don't see too 
> > much improvement:
> >
> > 1 word off ("return"), and "=>" instead of brackets.
>
> You've pretty much just summed up the argument not to introduce 
> lambda syntax. It has been proven wrong.

I think it is a good middle ground for predicates where I
don't like to use strings mixins instead of plain expressions:
  "a > b"
But the verbose D syntax is just too distracting:
  bool function(T a, T b) { return a > b; })
lambdas on the other hand save a lot of typing and have first
class language support:
  (a, b) => a > b
If some day we can omit the parameter list like in some other
language, I wouldn't mind.

-- 
Marco



More information about the Digitalmars-d mailing list