tc39 / proposal-iterator.range

A proposal for ECMAScript to add a built-in Iterator.range()

Home Page:https://tc39.es/proposal-iterator.range/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[a..b] and [a..n..b] syntax

oauo opened this issue · comments

commented

I made a range proposal where I outlined the use of [a..b] and [a..n..b] (and more complicated [a..n..m..b]) for creating ranges here: https://github.com/oauo/Range-Proposal

I basically want to say that I don't like the idea of [a...b] (3 "."s) because ... already has a meaning, and that it should be [a..b] (2 "."s) because it is unused and aligns with other languages (CoffeeScript, Haskell, F#)

Otherwise I would like to suggest the use of [a:b] and [a:n:b] as : doesn't have a meaning inside arrays, less ambiguous with decimals [1:.2:2.4], and shorter. It is also used in another language, R.

This proposal doesn't include a new syntax currently because IMO if it is not necessary, should be avoided.

The ... has its meaning. But .. also create an ambiguous context. For [1..toString()] and [1..2] the parser needs to scan to the char t or 2 to know it is a range syntax or property access.

The [a:b] syntax is used by the slice notation proposal

@Jack-Works The slice notation proposal and this proposal could both use the same notation, and they aren't mutually exclusive.

  • Slice notation is specific to property access.
  • This is specific to array values.
  • The two are no less ambiguous than a dynamic property access (foo[1]) vs a single-element array (foo; [1]), and this is something that's been around since ES3.

And IMO language precedent leans very strongly to either a concise builtin (Python, Haskell and friends) or native syntax (most other languages).

Edit: clarity

I think if a new syntax is really necessary, we can add it in the future after all. The current proposal should focus on the API shape and runtime semantics. Thanks for your suggestion!