Reuse 'do' keyword instead of hash sign (#)
Jack Moxley
jack at moxley.co.uk
Sun Jun 19 23:42:53 PDT 2011
I think its confusing, do implies immediacy.
On 19 Jun 2011, at 22:42, Steven Simpson <ss at comp.lancs.ac.uk> wrote:
> On 18/06/11 12:11, Marcin Wiśnicki wrote:
>> Would it be possible to change the clumsy '#' operator to 'do' keyword ?
>> I.e.:
>>
>> do()(5)
>
> The reasoning about optional brackets with the other syntaxes ought to
> apply here too, e.g.:
>
> do () 5
>
> do (x, y) x + y
>
>
>> Pros:
>> - more readable
>> - makes sense
>> - like '#' needs only 1-lookahead to disambiguate from do-while '(' vs '{' [1]
>
> 'do' is followed by a statement, not necessarily a block statement, so
> the sequence 'do (' is already allowed:
>
> String x = "yes";
>
> do (x).length(); while (false);
>
> ...though that's rather contrived.
>
> However, a lambda is most likely to be used in places where a do-while
> cannot. You can't write:
>
> Runnable r = do { ... } while (...);
>
> ...nor:
>
> process(do { ... } while (...));
>
> ...so, as a production of Expression, a lambda with a 'do' syntax should
> be safe.
>
> I think the only conflict is between a DoStatement and an
> ExpressionStatement. In that case, start with a bracket, and you
> immediately rule out do-while.
>
> Forbid this:
>
> do () { System.out.println("yes"); }.invoke();
>
> Permit this:
>
> (do () { System.out.println("yes"); }).invoke();
>
> And, of course, that's another rather useless contrivance, so you're not
> really losing out by having to provide extra brackets.
>
>
More information about the lambda-dev
mailing list