Block Lambdas: break and continue

Grant Husbands esdiscuss at grant.x43.net
Mon Jan 16 17:33:22 PST 2012


Brendan Eich wrote:
> 2. Variation on empty label: support "do" as a reserved-identifier label
>
>   do: arr.forEach {|o|
>     if (...) break;
>     ...
>   }

This seems like a sound way of doing it, indeed (I omitted your first
one because I prefer this one). It avoids the more egregious syntax
conflicts and is indicative of being interesting to break/continue.
Combined with the break-with and continue-with statements, elsewhere
in this thread, it makes block lambdas better than anonymous functions
currently are in nearly all cases, along with making it easier to
replace loops with callback-based iteration.

> 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.

Would it call that block-lambda with no arguments?

> 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.

I think I'm misreading, but I'm not seeing how "do:" and "return :"
conflict. If break-with and continue-with get specced, they would
cover the same use case, anyway. I do agree that if ":" could start an
expression and "do" could be used without braces, there would be a
conflict; maybe there could be significant whitespace in that
situation. I'm sure people more qualified than myself will cover this,
though.

I don't know how the process works, but I'd be happy to assist in the
creation of additional strawmen to cover these (potentially later)
additions to block lambdas and other blocks, if consensus is reached.
I don't want to jump the gun, though.

Oh, and I do agree that credit goes to Axel for the proposal.

Thanks,
Grant.


More information about the es-discuss mailing list