Syntax poll

Kieron.Wilkinson at paretopartners.com Kieron.Wilkinson at paretopartners.com
Mon Jun 13 05:03:15 PDT 2011


Sorry to nitpick, but I don't really think that was an error. They are 
both valid Scala syntax if you change the "->", and move the type 
declaration. That is, both of the following compile and run (Scala 2.8), 
given suitable Foo:

Scala/BGGA:

      list.filter( { t: Foo => t.length() > 3 } )
            .map( { t: Foo => t.barCount } )
            .max

Scala/Redmond:

      list.filter((t: Foo) => { t.length() > 3 } )
            .map((t: Foo) =>  { t.barCount } )
            .max

I'd actually say BGGA-style was slightly closer for this these 
one-argument lambdas, as it requires less redundant brackets. You could 
say Redmond-style is closer if you have multiple parameters though (where 
the brackets around the argument list is mandatory in Scala), but my only 
point is that I don't think it's a black and white case.

Of course, neither is particularly idiomatic Scala. That would be more 
like this:

    foos.filter(_.length > 3).map(_.barCount).max

Kieron


Brian Goetz <brian.goetz at oracle.com> wrote on 11/06/2011 20:40:42:
> 
> That is correct.  Scala's syntax is closer to "Redmond" than to "BGGA". 
>   Sorry for the error.
> 
> On 6/11/2011 3:31 PM, Pavel Minaev wrote:
> > Since the cat is out of the bag already, I feel the need to correct 
the
> > below (I did so privately to Brian, but it seems that the new poll has
> > quoted the old descriptions verbatim with no changes).
> >
> > BGGA syntax is used by Groovy. It's not used by Scala - the latter 
uses
> > Redmond syntax pretty much exactly as in C#, except that "type name" 
becomes
> > "name: type" in parameter declarations with non-inferred types
> > (corresponding to general Scala syntax). Here are some Scala lambdas:
> >
> > (x: Int, y: Int) =>  x + y
> > (x, y) =>  x + y // inferred types
> > x =>  x + 1 // can omit parens for unary lambda with unary types
> > () =>  { println("hello"); println("word"); }
> >
> > On Sat, Jun 11, 2011 at 12:06 PM, Llewellyn 
Falco<isidore at setgame.com>wrote:
> >
> >> BGGA is scala-groovy
> >> Redmond is C#
> >> I'm not sure about strawman
> >>
> >>
> >
> 


This message may contain confidential and privileged information and is intended solely for the use of the named addressee. Access, copying or re-use of the e-mail or any information contained therein by any other person is not authorised. If you are not the intended recipient please notify us immediately by returning the e-mail to the originator and then immediately delete this message. Although we attempt to sweep e-mail and attachments for viruses, we do not guarantee that either are virus-free and accept no liability for any damage sustained as a result of viruses.

Please refer to http://www.bnymellon.com/disclaimer/piml.html for certain disclosures.


More information about the lambda-dev mailing list