January 15, 2012 2:31 PM


We could try for other syntax, but it too would have the body-less problem. Unless we use a new keyword:

loop arr.forEach { |o|
  if (...) break;
}


Even though these are not necessarily "loops", I think loop is still a plausible keyword.

Couple of alternative-syntax thoughts:

1. Empty label as optional prefix to CallWithBlockArguments, to make the block-lambda argument(s) breakable or continuable:

  : arr.forEach {|o|
    if (...) break;
    ...
  }

The idea is that break or continue without label targets the nearest empty label or predefined target statement, whichever is closer. But I propose to narrow this to be a special prefix form only for CallWithBlockArguments.

In an _expression_ context the leading colon requires parenthesization if used in the consequent of a ternary (?:) _expression_. In an object literal's PropertyAssignment you'd get a confusing ": :" juxtaposition. So it probably is better to require parentheses around empty-label-prefixed calls in all expressions.

The continue case would exit the containing block-lambda argument to the :-labeled CallWithBlockArguments instead of exiting the whole CallWithBlockArguments _expression_.

2. Variation on empty label: support "do" as a reserved-identifier label that is implicitly addressed by break; and continue; (no labels on the break and continue). A little Smalltalk homage and not so visually nasty and potentiailly confusing as empty label.

  do: arr.forEach {|o|
    if (...) break;
    ...
  }

To complete the Smalltalk homage we would want this in expressions, and we'd also want do: to take a block-lambda directly, in addition to a CallWithBlockArguments.

This variation is future-hostile to leading-colon as statement- or _expression_-starting special forms (see http://wiki.ecmascript.org/doku.php?id=strawman:return_to_label). I think that this is acceptable but I could be missing something.

Comments welcome.

/be
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to