Reuse 'do' keyword instead of hash sign (#)

Steven Simpson ss at comp.lancs.ac.uk
Sun Jun 19 14:42:39 PDT 2011


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