On Nov 23, 2010, at 5:19 AM, P T Withington wrote: > On 2010-11-22, at 02:37, David Herman wrote: > >> if we allowed for-in to be overloaded, I would tell people that they should >> deprecate the legacy for-in and replace it with an explicit iterator such as: >> >> for (x in keys(obj)) > > I have learned a mnemonic for for-in: that it is iterating using the `in` > operator. You propose that I unlearn that? Or in your new hypothetical > world does the `in` operator also get overloaded?
Excellent question. One (Java extension language) answer: http://www.cs.cornell.edu/Projects/jmatch/ Python allows unstratified meta-programming of both its for-in loop/comprehension syntax *and* its |in| operator. Harmony Proxies allow meta-programming of |in| already, via the |has| trap. So the answer to your quesiton "does the `in` operator also get overloaded?" is "Yes, but you have to write two traps, iterate and has". > Ramdom thought: Can I use destructuring in for-in? > > for ({key:value} in enumerable) > > for ([value] in iterable) Absolutely. Destructuring (separate proposal but composes well) applies to all LHS and binding forms. /be _______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

