Ranges

Tab Atkins Jr. jackalmage at gmail.com
Tue Dec 13 23:53:27 UTC 2016


On Tue, Dec 13, 2016 at 3:07 AM, Hikaru Nakashima
<oao.hikaru.oao at gmail.com> wrote:
> My idia is as follows:
>
> ```
> [1..5]  //-> [1,2,3,4,5]
>
> (1..5)   //-> iterate 1, 2, 3, 4, 5
>
>
> [1..Infinity]  // -> TypeError because n > 2**32-1
>
> (1..Infinity)  // -> valid iterator
> ```

As Andy just explained in the previous message, that doesn't work.  In
particular, `[1..end]` is equivalent to `[(1).end]`, which is a
perfectly valid expression that creates a length-1 array containing
the value of the "end" property from a Number wrapper auto-constructed
around 1.  (Which happens to be undefined, unless you do shenanigans.)

~TJ


More information about the es-discuss mailing list