Syntax options

Howard Lovatt howard.lovatt at gmail.com
Tue Jun 21 00:42:38 PDT 2011


I too like the Ali Ebrahimi form, a unary and a binary -> operator with the
same precedence as = and which binds right to left like =, since it is the
least visually intrusive, is similar to Scala and C#, and reminiscent of the
declaration syntax in Haskell:

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

Statement form:
 Nilary example: -> { return 3; }
 Unary example: x -> { return x + 1; }
 Binary example: (x, y) -> {
    if (x) { return y + 1; }
    return y;
 }
 Curry example: x -> { y -> { return x + y; } }

Notes:
1.  When comparing syntaxes it is useful to include the curry form since
this does occur with reasonable frequency in languages with lambdas; in an
extreme case like Haskell everything is curried.
2. All the syntaxes would be improved if Java adopted the rule that a ; was
optional before a } throughout the language, i.e. a ; or } terminates a
statement.

 -- Howard.

On 21 June 2011 16:52, Bob Foster <bobfoster at gmail.com> wrote:

> On Mon, 20 Jun 2011 11:46:46 -0400 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.
> > ...
>
> Thanks, Brian. The survey examples suffered from zeroOrOneArgument-itis.
> You've corrected that best for Redmond. Much appreciated.
>
> I prefer Ali Ebrahimi's proposal, which I believe is Redmond as you
> describe
> with no variants or options except that the nilary examples are modified
> to:
>
> Expression form:
>  Nilary example: -> 3
>
> Statement form:
>  Nilary example: -> { return 3 }
>
> His proposal appears to reduce the syntax to its bare bones without
> reducing
> clarity. A similar thing could be done with the # prefix notation, but I
> find the infix -> notation less jarring to the eye and, as you said in the
> survey, there is some precedent for it in Scala.
>
> I realize that grammars aren't appropriate for quick take-the-pulse
> surveys,
> but in the aftermath Ali Ebrahimi has done us all a favor by providing a
> grammar to clarify his modest and simplifying departure from Redmond, as
> quoted below:
>
> On Mon, 20 Jun 2011 12:42:52 +0330 Ali Ebrahimi wrote:
> >
> > Hi,
> > And this is full grammar:
> >
> > LambdaDeclaration =
> >                    LambdaParameterList '->' LambdaBody
> >
> > LambdaParameterList =
> >        LambdaParameter? | '(' ( LambdaParameter ( ',' LambdaParameter )*
> )? ')'
> >
> > LambdaParameter =
> >        Parameter | Identifier
> >
> > LambdaBody =
> >        Expression | `{' Statement* `}'
>
> Bob
>
>


-- 
  -- Howard.


More information about the lambda-dev mailing list