return when desugaring to closures

Brendan Eich brendan at
Mon Aug 25 18:27:23 PDT 2008

On Aug 25, 2008, at 6:15 PM, Mark S. Miller wrote:

> Thanks, that helps a lot. But shouldn't that "i == n" be "!(i < n)"
> since it's a transform of the original "i < n"?

Sure -- was going fast (other work competing ;-).

> On Thu, Aug 21, 2008 at 11:31 PM, Dave Herman <dherman at>  
> wrote:
>> Can't be done without defining the entire language in CPS. Yes, it's
>> shallow, but a captured activation can involve any arbitrary  
>> combination of
>> expressions other than function call.
> Dave, is the violent transform of the for-loop above the kind of
> rest-of-the-language transform you were referring to?

Answering for Dave: yes.

> If so, isn't
> this only an issue for control structures (including &&, ||, and ?:)?
> What other elements of the language might need to be turned inside out
> this way? Or have I misunderstood what you're getting at.

As in Python 2.5, JS1.7 and up support yield expressions too. These  
return values and resume with new values when the generator is  
continued via next (which sends undefined) or send(v) (arbitrary v).  
The simple_range example I showed happened to use yield as an  

I don't expect we'll CPS-transform any future ES spec, but you are  
entitled to pain if you like it ;-).


More information about the Es-discuss mailing list