Syntax options
Mikael Grev
grev at miginfocom.com
Mon Jun 20 09:41:54 PDT 2011
is it totally out of the question to optionally be able to use a short hand like for instance:
#{ $1.length() > 1 }
?
On Jun 20, 2011, at 17:46 PM, Brian Goetz wrote:
> 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