Optional brackets around lambda expression
Pavel Minaev
int19h at gmail.com
Wed Jun 15 15:40:46 PDT 2011
To be honest, I'm not sure what Brian specifically meant by "Redmond syntax"
there. All his examples did, indeed, use braces, but the name implies
general correspondence to C# syntax, and C# doesn't require them.
Brian, can you clarify whether the presence of braces in all examples there
was intentional (i.e. you consider it an integral part of that syntax), or
it is a discussion point in any further debate (should this syntax be picked
as preferred)?
On Wed, Jun 15, 2011 at 2:25 PM, Steven Simpson <ss at comp.lancs.ac.uk> wrote:
> On 15/06/11 21:42, Pavel Minaev wrote:
> > Note that this applies also to "Redmond syntax" in general; e.g.:
> >
> > new User().use(x => x + "a string");
>
> Ah - I only looked at the options in the original "Syntax poll", where
> expressions were in braces for Redmond.
>
> > On Wed, Jun 15, 2011 at 1:35 PM, Yuval Shavit <yshavit at akiban.com
> > <mailto:yshavit at akiban.com>> wrote:
> >
> > What would happen with something like:
> >
> > public interface Sam {
> > String doSomething(String arg);
> > }
> > public class User {
> > public void use(Sam sam) { System.out.println("saw a sam"); }
> > public void use(String string) { System.out.println("saw a
> > string"); }
> > }
> >
> > new User().use( #(x) x + "a string" );
> >
> > In that context, which are we passing?
> > - lambda that takes a String, concatenates "a string" to it and
> > returns
> > the result
> >
>
> Yes.
>
> > - a string consisting of (lambda x -> x).toString() concatenated
> > with "a
> > string"
> >
>
> For that, you write (#(x) x) + "a string" - ordinary expression brackets
> can still be used, but are only necessary in the more contrived cases.
>
>
>
More information about the lambda-dev
mailing list