On 2010-11-23, at 14:14, Brendan Eich wrote:

> 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".

How does the `in` in for-in decide which of it's overloaded meanings applies?  
Based on the type of the operand?  Based on the existence of the enumerate or 
iterate trap on the operand?

And despite the `in` in for-in either enumerating or iterating, the `in` 
operator only has a single associated trap.  The non-parallelism is bugging me. 

>> 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.

I was being too subtle.  I was suggesting something like your JS 1.7 example, 
where the 'top-level' destructuring is a pattern for the `in` operation.  
`{key: value}` means I want the property keys and their values, `[value]` means 
I want the values, and `key` is (backward-compatible) shorthand for `{key: _}`. 
 Destructuring iteration over an hash of triples:

  for ({key: [s, v, o]} in tripledb) ...

Too cute?
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to