Block Lambdas: break and continue

Brendan Eich brendan at
Mon Jan 16 14:16:58 PST 2012

> Allen Wirfs-Brock <mailto:allen at>
> 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 

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 

This variation is future-hostile to leading-colon as statement- or 
expression-starting special forms (see I 
think that this is acceptable but I could be missing something.

Comments welcome.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: postbox-contact.jpg
Type: image/jpeg
Size: 1293 bytes
Desc: not available
URL: <>

More information about the es-discuss mailing list