Day 2 meeting notes

Brendan Eich brendan at mozilla.com
Fri Jul 30 14:10:06 PDT 2010


On Jul 30, 2010, at 12:06 PM, felix wrote:

> actionscript 3 has
>  for (key in a) {}
>  for each (val in a) {}

This is from ECMA-357, E4X, and it is in SpiderMonkey and Rhino too -- it's not original to AS3.

It's also something we agreed (crock too, IIRC) was too vague: "each" does not scream "value, not key".

But beyond that, iteration in general is not necessarily visiting properties in an object, and then you have to choose an obscure keyword or preposition to choose value or key. Iteration is a stream of values, no properties needed at all.

In that light, and in light of Mathematics as well as Python and JS1.7+, it is hard to beat "for ... in ...". "For all elements in set", "for all items in list", "for all [key, value] pairs in dict", etc.

This might suggest using "all", but that too is vague, and it also may suggest eagerness or completeness. But iteration is needed in JS precisely for laziness.

Infinite sequences or streams where the consumer decides when to stop asking for the next value are currently underserved use-cases. This point came up when reviewing

http://wiki.ecmascript.org/doku.php?id=harmony:proxies
 Waldemar raised objections against the current Proxy API to proxy objects with a large number of properties. The problematic traps are fix and enumerate. W.r.t enumerate, a proxy could return a proxy for an array. Additionally, enumerate should be modified as soon as there is a solid proposal for generators/iterators. Proxies for large objects could resist being fixed. This solution is satisfactory as long as no part of the spec depends on an object being non-extensible/sealed/frozen.
Of course this does not say what the syntax for a meta-programmable iteration construct should be, but laziness suggests "all" is not precisely on target.

/be
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20100730/f5e62ee7/attachment.html>


More information about the es-discuss mailing list