Block Lambdas: break and continue

Grant Husbands esdiscuss at grant.x43.net
Sun Jan 15 03:51:28 PST 2012


Brendan Eich wrote:
> More when I reply to Axel in a bit.

I think there may have been a misunderstanding. My proposed solution
amounts to syntactic sugar over the existing strawman and makes
break/continue work intuitively with loopy block lambdas, and your
reply to Axel appears to be against an exception-based version, but
you seem to have (implicitly) tied them together.

> Of course we want to uphold TCP, which constrains the design. What works
> here must work in a regular block statement as body of such a loopish
> structure.

Well, the LCP (Loop Correspondence Principle :) is maintained. So, you
can change your loop construct from:
for (var i=0; i<arr.length; ++i) {
  var o = arr[i];
  if (...) break;
}

To this:
for arr.ForEach { |o|
  if (...) break;
}

And it still works, without needing to throw exceptions or alter the
existing library code. I believe TCP to be maintained everywhere it
might apply, not least because there's a syntactic opt-in, but I may
have missed what you're pointing out.

If the syntax conflicts disastrously with paren-free, then a suitable
nearby syntax could be chosen. I'm not attached to the syntax; I'm
simply offering an implementation strategy that's minimal, matches
most requirements and doesn't appear to break any of the imposed
rules; I don't know the other strawman proposals well enough to avoid
conflicting syntax. It's a boolean toggle, though, so it should be
easy to find a suitable syntax.

Regards,
Grant Husbands.


More information about the es-discuss mailing list