Syntax options
John Nilsson
john at milsson.nu
Mon Jun 20 09:03:56 PDT 2011
Could the braces around the BGGA variant be optional? At lest for
expressions?
The result would be similar to the redmond variant exept that the left curly
would come before the argument list in statement form.
BR,
John
Sent from my phone
Den 20 jun 2011 17:50 skrev "Brian Goetz" <brian.goetz at oracle.com>:
> 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