Ranges

Alexander Jones alex at weej.com
Fri Nov 4 10:11:42 UTC 2016


+1000

Classic feature creep with basically zero application.

On Thursday, 3 November 2016, Isiah Meadows <isiahmeadows at gmail.com> wrote:

> Could we just *not* have a `String.range`?
>
> 1. Needing a list of alphabetically sorted characters is a bit niche, even
> in the Latin alphabet.
> 2. It's ambiguous whether it should include symbols or not. (think:
> `String.range("A", "z")`)
> 3. If it's Unicode-aware, how should it act with, say, `String.range("A",
> "π")`?
>
> On Thu, Nov 3, 2016, 16:21 Viktor Kronvall <viktor.kronvall at gmail.com
> <javascript:_e(%7B%7D,'cvml','viktor.kronvall at gmail.com');>> wrote:
>
>> Even more interestingly what would `String.range("","zzz")` produce. From
>> what code point is the range started? Will this throw? Is the empty string
>> included in the iterator?
>> 2016年11月3日(木) 21:18 Viktor Kronvall <viktor.kronvall at gmail.com
>> <javascript:_e(%7B%7D,'cvml','viktor.kronvall at gmail.com');>>:
>>
>>> Actually, after giving it some more thought for that case there is just
>>> that one possibility that makes sense.
>>>
>>> However, there are more ambiguous cases such as `String.range("AAA",
>>> "ZZZ")` (should all letters increase at once or should the rightmost letter
>>> be incremented first)
>>>
>>> Also, how would range handle the arguments in inverted order? Should
>>> there be a decreasing range or should it terminate with no elements in the
>>> iterator?
>>> 2016年11月3日(木) 21:05 kdex <kdex at kdex.de
>>> <javascript:_e(%7B%7D,'cvml','kdex at kdex.de');>>:
>>>
>>>> About the code points: `String.range` should also handle surrogate
>>>> pairs, similar to for..of does it.
>>>> About `String.range("A", "zzz")`: Do any other possibilities even make
>>>> sense?
>>>>
>>>> On Thursday, November 3, 2016 6:47:04 PM CET Viktor Kronvall wrote:
>>>> > For `String.range` what would the expected result of
>>>> > `String.range('A','zzz')` be?
>>>> >
>>>> > Is an exhaustive pattern expected?
>>>> >
>>>> > `['A','B','C',...'Z','a','b','c',...,'z','AA','AB',...]`
>>>> > 2016年11月3日(木) 19:21 Michael J. Ryan <tracker1 at gmail.com
>>>> <javascript:_e(%7B%7D,'cvml','tracker1 at gmail.com');>>:
>>>> >
>>>> > > If there's a Number.range, if suggest a corresponding String.range
>>>> for
>>>> > > character ranges...  Agreed on it being a utility function over me
>>>> syntax.
>>>> > >
>>>> > > On Nov 3, 2016 10:25 AM, "Isiah Meadows" <isiahmeadows at gmail.com
>>>> <javascript:_e(%7B%7D,'cvml','isiahmeadows at gmail.com');>> wrote:
>>>> > >
>>>> > > If string ranges are based on character codes, it will (for the
>>>> Latin
>>>> > > alphabet, at least, not necessarily for other languages).
>>>> > >
>>>> > > I would prefer a function over syntax, though, since it would be
>>>> more
>>>> > > easily adopted (polyfill > syntax), and it would fit more
>>>> idiomatically
>>>> > > with the rest of the language (which also uses functions for most
>>>> > > utilities).
>>>> > >
>>>> > > Maybe a `Number.range` would work?
>>>> > >
>>>> > > ```js
>>>> > > Number.range = function *range(start, end=undefined, step=1) {
>>>> > >   if (end === undefined) [start, end] = [0, start];
>>>> > >   if (end === undefined) end = Infinity;
>>>> > >   for (let i = 0; i < end; i += step) {
>>>> > >     yield i;
>>>> > >   }
>>>> > > };
>>>> > > ```
>>>> > >
>>>> > > On Thu, Nov 3, 2016, 12:56 kdex <kdex at kdex.de
>>>> <javascript:_e(%7B%7D,'cvml','kdex at kdex.de');>> wrote:
>>>> > >
>>>> > > Agreed. There's no reason why `Array.range` or `[1..10]` couldn't
>>>> just
>>>> > > return a generator
>>>> > > or at least something that extends a generator, though. I wonder if
>>>> it's
>>>> > > viable to implement
>>>> > > something akin to `.length` on ranges, which could be natural
>>>> numbers or
>>>> > > `Infinity`.
>>>> > >
>>>> > > As for numbers, I don't see any issues. One issue that came up in
>>>> the
>>>> > > original thread was
>>>> > > that string ranges may need a better definition, as ["A".."C"]
>>>> might not
>>>> > > necessarily transpile
>>>> > > to be a generator that yields "A", "B" and "C".
>>>> > >
>>>> > > On Thursday, November 3, 2016 4:46:03 PM CET Isiah Meadows wrote:
>>>> > > > I'll note, just for clarity, that Scala's `1 to 10` is
>>>> technically just a
>>>> > > > normal method call equivalent to `(1).to(10)`, with optional
>>>> parentheses
>>>> > > > removed.
>>>> > > >
>>>> > > > Also, I'd prefer this to be a generator instead, so infinite
>>>> ranges are
>>>> > > > also possible, and so it doesn't have to be eager.
>>>> > > >
>>>> > > > On Thu, Nov 3, 2016, 11:52 Hikaru Nakashima <
>>>> oao.hikaru.oao at gmail.com
>>>> <javascript:_e(%7B%7D,'cvml','oao.hikaru.oao at gmail.com');>>
>>>> > > > wrote:
>>>> > > >
>>>> > > > > How about this
>>>> > > > >
>>>> > > > > ```
>>>> > > > > for ( i of Array.range(1, 10) ) { ... }
>>>> > > > > // OR
>>>> > > > > for ( i of [1..10] )  { ... }
>>>> > > > > ```
>>>> > > > >
>>>> > > > >
>>>> > > > > _______________________________________________
>>>> > > > > es-discuss mailing list
>>>> > > > > es-discuss at mozilla.org
>>>> <javascript:_e(%7B%7D,'cvml','es-discuss at mozilla.org');>
>>>> > > > > https://mail.mozilla.org/listinfo/es-discuss
>>>> > > > >
>>>> > > >
>>>> > > _______________________________________________
>>>> > > es-discuss mailing list
>>>> > > es-discuss at mozilla.org
>>>> <javascript:_e(%7B%7D,'cvml','es-discuss at mozilla.org');>
>>>> > > https://mail.mozilla.org/listinfo/es-discuss
>>>> > >
>>>> > >
>>>> > > _______________________________________________
>>>> > > es-discuss mailing list
>>>> > > es-discuss at mozilla.org
>>>> <javascript:_e(%7B%7D,'cvml','es-discuss at mozilla.org');>
>>>> > > https://mail.mozilla.org/listinfo/es-discuss
>>>> > >
>>>> > > _______________________________________________
>>>> > > es-discuss mailing list
>>>> > > es-discuss at mozilla.org
>>>> <javascript:_e(%7B%7D,'cvml','es-discuss at mozilla.org');>
>>>> > > https://mail.mozilla.org/listinfo/es-discuss
>>>> > >
>>>>
>>>> _______________________________________________
>>>> es-discuss mailing list
>>>> es-discuss at mozilla.org
>>>> <javascript:_e(%7B%7D,'cvml','es-discuss at mozilla.org');>
>>>> https://mail.mozilla.org/listinfo/es-discuss
>>>>
>>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> <javascript:_e(%7B%7D,'cvml','es-discuss at mozilla.org');>
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20161104/087ee4ac/attachment.html>


More information about the es-discuss mailing list