Block Lambdas: break and continue

Grant Husbands esdiscuss at grant.x43.net
Sun Jan 15 08:00:07 PST 2012


Brendan Eich wrote:
> I don't see how your proposal can work without exceptions. You write that
> it is syntactic sugar. Ok, what is the desugaring? How does
>
> for arr.ForEach { |o|
>   if (...) break;
> }
>
> translate into JS without a throw that the implementation of arr.forEach,
> which is not modfiied by this for-prefixed invocation, can catch?

The above would desugar to:
label1: arr.ForEach { |o|
  if (...) break label1;
}

If it had continue instead of break, it would desugar to:
arr.ForEach { |o|
  label2: {
    if (...) break label2;
  }
}

It wouldn't need to be described as a desugaring in a strawman, given
the similarity to typical break/continue handling, but I think that
makes the meaning clear.

Regards,
Grant Husbands.


More information about the es-discuss mailing list