tc39 / proposal-slice-notation

http://tc39.es/proposal-slice-notation/
MIT License
523 stars 18 forks source link

Using tuples proposal: arr[#[a,b]] instead of arr[a:b] #44

Closed caub closed 3 years ago

caub commented 3 years ago

The benefit is to not introduce new syntax

Tuple proposal: https://github.com/tc39/proposal-record-tuple

This idea comes from @brigand

What do you guys think about using tuples notation for this proposal? They'd be used in arrays property accessors, and return a slice

ljharb commented 3 years ago

Assuming Tuples already existed, that would already be the same as:

const t = #[a, b];
arr[t]

iow, inside the brackets, any expression is already legal - so the only syntactic options are something that’s a syntax error already in expression position. So, for your syntax to work, Tuple syntax wouldn’t be able to.

caub commented 3 years ago

@ljharb arr[#[0,2]] would be valid syntax when tuple are added in the spec. I was thinking that the spec could then allow a special behavior for array[tuple] since tuples are new, there would be no backward-compatibility issues.

But after more thoughts, this syntax is heavy anyway, it doesn't look that appealing

ljharb commented 3 years ago

There would be consistency issues, though.

caub commented 3 years ago

ok, thanks, closing