Block Lambdas: break and continue

Grant Husbands esdiscuss at
Sat Jan 14 14:51:16 PST 2012

Brendan Eich wrote:
> > Exception handling is seldom used in the large except to void the
> > exception.
> And then only near or at a top-level event loop.
> Exception handling is the issue here, because of the proposal to add
> reifed break and continue as thrown exceptions. How exception
> handling is practiced (usually not) is highly relevant.

I agree that exceptions might not be the way to handle it. I've seen
it noted that something like these would work under the existing

forEach(arr) { |a|
  skip: {
  	// ...
  	if (...) break skip; // Equivalent to continue

end: forEach(arr) { |s|
  // ...
  if (...) break end; // Equivalent to break

The mechanism by which they work may give a more agreeable path for
implementation of the new kind of end/break, perhaps along with a
keyword near the forEach to enable the behaviour. It would also mean
that break/continue could still be matched with their jump-sites at
compile time. There'd be the caveat that the iterating function would
have no control over that flow, but that is already the case for
continue/break/return under the existing proposal.

To try to be clear, I'm implying a syntax akin to this could give the
desired break/continue functionality for lambda-block-based loops, and
could essentially desugar to the above:
for forEach(arr) { |a|
  // ...
  if (...) continue;
  if (...) break;

It would probably need alteration to not conflict with other recent syntax.

Grant Husbands.

More information about the es-discuss mailing list