Concise functions, Nonexistent lambdas, Explicit tail calls

Brendan Eich brendan at mozilla.com
Tue Dec 9 23:41:44 PST 2008


On Dec 9, 2008, at 8:59 PM, Jon Zeppieri wrote:

> Since there is no updateExpr to worry about, that isn't a problem.
> The real problem with for/in is that the set of property names can
> change under you as the loop executes.

You're guaranteed not to see ids deleted after the loop started. The  
spec leaves undefined whether you see added names. Real  
implementations that I know do not show added names.

Enumeration order is also unspecified. The big issue among  
implementors I talk to is whether only Arrays, or all objects with  
indexed properties, use index order rather than insertion order. I'm  
increasingly in favor of index order, which almost always matches  
insertion order. Where there's no agreement among browsers (e.g., for  
an array with named and indexed properties), we could hope to  
standardize on a specific total order.

For JS1.7+ and (I hope) Harmony, for-in constructs are built on a  
Pythonic iteration protocol, likewise for-each-in (just using a  
different iterator). Everything, arrays, DOM nodelists, objects  
representing various kinds of collections, could have an __iterator__  
hook (name TBD, __iter__ is the Python name). Calling it gets you the  
iterator for that object (iterators return themselves). An iterator  
has only a .next() method and throws StopIteration (a singleton  
exception object) to stop iteration.

Generators (functions that yield, as in Python) are factories for  
iterators that resume the function at the entry point or after the  
last yield when .next() is called. It's actually easier to model for- 
in and for-each-in as generator-based, and then specify generators  
using primitives. The ES4 RI used delimited continuations in SML-NJ,  
thanks to Dave Herman.

This was detailed in a couple of ways for ES4, most successfully by  
Jason Orendorff (with a patch to the RI), but the fundamental design  
doesn't depend on ES4-isms.

I'd like to take a fresh run at strawman:iteration over the holidays.  
Thoughts welcome,

/be


More information about the Es-discuss mailing list