transparent lambda
Peter Levart
peter.levart at marand.si
Thu Jan 7 23:50:19 PST 2010
On Friday 08 January 2010 01:55:15 Neal Gafter wrote:
> On Thu, Jan 7, 2010 at 4:10 PM, Peter Levart <peter.levart at gmail.com> wrote:
>
> > I would not put labeled block expression in the list of possible
> > StatementExpressions.
> >
> > So the only syntactically correct interpretation of the above example would be "a labeled block statement followed by an empty statement".
> >
> > Am I missing something?
> >
> > Peter
> >
>
> Yes. Can an expression statement *start* with a labeled expression?
>
> label : { ... }
> (expression) . f ();
>
> Is the parenthesized expression an argument to the labeled block expression
> (which must be of function type), or the start of a new statement?
>
> We can go on and on here, but the fundamental point is: it is a bad idea to
> have a single syntax be ambiguous between a statement form and an expression
> form.
Ok, I see the point. So what about a different syntax?
Let's take the block expression as defined by CfJ 0.6b. That is one form of block expression, let's call it "unlabeled block expression":
(S; E)
Could we introduce another form called "labeled block expression":
label:(S;) // I see the point in keeping expression/statement syntaxes separate ;-)
The later being a shortcut for:
(Type retval; label:S; retval)
Where a special value-bearing break:
break label : expression;
is a shortcut for
{ retval = expression; break label; }
and the Type being a reduction of all types of expressions present on value-bearing breaks.
for example this:
label:(
if (a < b) break label : -1;
if (a > b) break label : 1;
break label : 0;
)
is equivalent to this:
(int retval; label:{
if (a < b) { retval = -1; break label; }
if (a > b) { retval = 1; break label; }
{ retval = 0; break label; }
} retval)
Ok, I see one hard to read expression:
a ? b : c : (...)
But is it ambigous? If it is not then it could be rewritten to be more obvious to human eye:
a ? b : (c : (...));
Many expressions do not need parentheses but are parenthesized for the purpose of clarity.
>
> Cheers,
> Neal
>
Regards, Peter
More information about the closures-dev
mailing list