I don’t like the implicit iteration of the operand that happens for yield*
this.left. To me, superficially, it looks like this.left is yielded. Instead,
it is more a self-recursive call. Compare:
function visit(visitor) {
if (this.left) {
iterFunc(this.left, visitor);
}
visitor(this.label);
if (this.right) {
iterFunc(this.right, visitor);
}
}
function* iterate() {
if (this.left) {
yield* iterGen(this.left);
}
yield this.label;
if (this.right) {
yield* iterGen(this.right);
}
}
Tree.prototype.visit = visit;
Tree.prototype[iterator] = iterate;
On May 10, 2012, at 21:32 , Brendan Eich wrote:
> Jason Orendorff wrote:
>> On Wed, May 9, 2012 at 2:07 AM, Axel Rauschmayer<[email protected]> wrote:
>>> Nice. It took me a few moments to figure out what is going on, though. I
>>> would prefer the following – slightly more explicit – code:
>>> if (this.left) {
>>> yield* this.left[iterator]();
>>> }
>>> Instead of:
>>> if (this.left) {
>>> yield* this.left;
>>> }
>>>
>>> That example also demonstrates why the @ notation makes sense:
>>> this.left.@iterator()
>>
>> Hmm. It seems like the language should accept anything iterable there,
>> so that you can just say:
>>
>> if (this.left)
>> yield* this.left;
>>
>> I think if you have to call a .iterator method explicitly in the
>> course of doing simple stuff like this, we've gotten something wrong.
>
> AGREED.
>
> Ahem.
>
> /be
>
--
Dr. Axel Rauschmayer
[email protected]
home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss