Syntax options

Brian Goetz brian.goetz at oracle.com
Mon Jun 20 08:46:46 PDT 2011


Several people have asked for clarification about the bounds of the 
various families of syntax options that were suggested in the poll. 
Here's an attempt to flesh out the option space for the families of 
options we've been discussing.

All forms allow type arguments to be omitted if they can be inferred.

Method reference syntax to be treated separately; if we choose a #-ful 
lambda form, then we should similarly choose a #-ful method reference 
form.

This isn't even a complete list of the various tweaks that can be 
applied.  The point here is simply to outline the space of possibilities 
that are under active discussion.


STRAWMAN
--------

Expression form: #(x)(x + 1)
Statement form: #(x){ if (x > 0)
                           return 1;
                       else
                           return 2;
                     }

Variant 1: use same delimiter (curly braces) for both statement and 
expression lambdas

Variant 2: Variant 1, plus nilary form: #{ 42 }

Option A: Some other prefix character:
    ^ (a la ObjC): ^(x){ x+1 }
    ` (a la lisp): `(x){ x+1 }
    & (a la C++):  &(x){ x+1 }
    etc


BGGA
----

Expression form: { x -> x + 1 }
Statement form: { x ->
                       if (x > 0)
                           return 1;
                       else
                           return 2;
                 }
Nilary form: { -> stuff }

Variant 1: require parens around arg lists in some cases (such as 
statement lambdas with "long" parameter lists):
   { (int a, int b, int c) ->
       if (a > b)
           return c;
       else
           return -c;
   }

Option A: Same, but with fat arrow =>

Option B: Always allow optional parens around arg list


SotL
----

This is BGGA with a prefix character glued on front.

Expression form: #{ x -> x + 1 }
Statement form: #{ x ->
                       if (x > 0)
                           return 1;
                       else
                           return 2;
                 }
Nilary form: #{ stuff }

Option A: Same, but with fat arrow =>

Option B: Some other prefix character:
    ^ (a la ObjC): ^{ x -> x+1 }
    ` (a la lisp): `{ x -> x+1 }
    & (a la C++):  &{ x -> x+1 }
    etc


Redmond
-------

Expression form: args -> expression
   Nilary example: () -> 3
   Unary example:  x -> x+1
   Binary example: (x,y) -> x+y

Statement form:  args -> { statements }
   Unary example:  x -> {
                       if (x > 0)
                           return 1;
                       else
                           return 2;
                   }

Variant 1: require braces (or parens) around expression form

Option A: Same, but with fat arrow =>

Option B: Require parens around arg lists always, including unary




More information about the lambda-dev mailing list