Fwd:Re:Why no placeholder shortcuts for lambdas?
Ben Evans
benjamin.john.evans at gmail.com
Tue Mar 6 12:07:07 PST 2012
Sorry- that should have gone back to list
---------- Forwarded message ----------
From: "Ben Evans" <benjamin.john.evans at gmail.com>
Date: Mar 6, 2012 8:05 PM
Subject: Re:Why no placeholder shortcuts for lambdas?
To: "Antoras" <mail at antoras.de>
In short, read the list archives. There is extensive discussion about this.
Short version: Not everyone agrees that maximum brevity is a thing to aim
for.
It hasn't always worked out well - see some of Perl's design decisions.
Even Scala can't honestly be considered enough of a mainstream language yet
to validate its closure syntax as viable yet.
Thanks,
Ben
On Mar 6, 2012 7:57 PM, "Antoras" <mail at antoras.de> wrote:
> I'm wondering why the shortcuts for lambdas are not as short as they can
> be.
>
> For example I get the following to work:
>
> xs.foldLeft(0, (i1, i2) -> i1 + i2);
> xs.foldLeft(0, ListTest::add);
>
> static int add(int i1, int i2) {
> return i1+i2;
> }
>
> where xs is a list of ints, foldLeft a method of this list and add a
> method in a class ListTest. But what was the design decision to disallow
> the following:
>
> xs.foldLeft(0, (+))
> // or
> xs.foldLeft(0, (_+_))
> // => (obj1).+(obj2) for objects
> // => (prim11)+(prim2) for primitives
>
> where + can be a method of an object or an operation on primitives and _
> any placeholder.
>
> Is this technically impossible or are there other reasons?
>
> Thanks in advance
> Antoras
>
>
More information about the lambda-dev
mailing list