W3C home > Mailing lists > Public > public-script-coord@w3.org > October to December 2013

Re: How to correctly spec sequences requiring an iterable

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Mon, 18 Nov 2013 10:50:18 -0800
Message-ID: <CAAWBYDALzoE0S5L49FwsdZCRwO5_F4=0o1+E8KeWy3KN4hjw8Q@mail.gmail.com>
To: Boris Zbarsky <bzbarsky@mit.edu>
Cc: "public-script-coord@w3.org" <public-script-coord@w3.org>
On Mon, Nov 18, 2013 at 9:59 AM, Boris Zbarsky <bzbarsky@mit.edu> wrote:
> My current plan in WebIDL is to spec sequence<> as follows, with the
> incoming value as "val":
>
> 1) If val is not an object, move on to the next union member (or throw
>    an exception if none left).  This allows a union of sequence and
>    string, and is the current behavior of sequences anyway.
> 2) Do iter = Get(val, @@iterator).  ReturnIfAbrupt.
> 3) If the value is not an object or is not callable, move on to the
>    next union member.
> 4) Commit to treating this as a sequence.
> 5) iterator = iter.call(val);
> 6) Walk through with IteratorStep/IteratorValue etc, converting each
>    sequence element before stepping to the next one.
>
> Does anyone see any obvious problems with that other than the
> (controversial) object check in step 1?

Nope, I like this.

Speaking from personal experience, while I appreciate that strings are
iterators, I treat them as non-iterable objects so much more often,
and regularly get tripped up by Python when I accidentally pass a
string to a method expecting an iterator, instead of wrapping it in a
tuple first.  As long as I can do "foo(String(str))" to get it to
iterate over the characters when I need to, I'm fine with this.

~TJ
Received on Monday, 18 November 2013 18:51:05 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:14:19 UTC