I can't see in the explainer document exactly what the semantics are when slices are created on various types of objects. But at a minimum, I'd expect a slice of an Array to produce an Array, and a slice of a String to produce a String. Python has these semantics, and I believe both of those two cases are useful.
Here's a straw-person of what the semantics would be: x[a:b:c] desugars into x[Symbol.slice](a, b, c). If there are arguments missing, they are filled in with undefined. If only one colon is used, the semantics are calling the method with two arguments. Then, Array.prototype and String.prototype have methods for Symbol.slice.
I understand that adding other well-known symbols which intercept aspects of existing behavior has been difficult from an implementation perspective. Here, it's a bit different--the new semantics are pretty simple (just like calling any other method) and no existing code paths have to be updated (just new ones).
Even if you go with semantics other than this, I think it'd be useful to come up with some sort of draft semantics or other before presenting this proposal to the committee, as it is likely to make the discussion more productive.
I can't see in the explainer document exactly what the semantics are when slices are created on various types of objects. But at a minimum, I'd expect a slice of an Array to produce an Array, and a slice of a String to produce a String. Python has these semantics, and I believe both of those two cases are useful.
Here's a straw-person of what the semantics would be:
x[a:b:c]desugars intox[Symbol.slice](a, b, c). If there are arguments missing, they are filled in withundefined. If only one colon is used, the semantics are calling the method with two arguments. Then,Array.prototypeandString.prototypehave methods forSymbol.slice.I understand that adding other well-known symbols which intercept aspects of existing behavior has been difficult from an implementation perspective. Here, it's a bit different--the new semantics are pretty simple (just like calling any other method) and no existing code paths have to be updated (just new ones).
Even if you go with semantics other than this, I think it'd be useful to come up with some sort of draft semantics or other before presenting this proposal to the committee, as it is likely to make the discussion more productive.