17132, “vasslitvinov”, “Range slicing syntax”, “2021-02-09T08:17:53Z”
This issue asks whether we can improve the way range slicing is written.
In our range module review on 2/04 a few of us noted that the current way to slice a range unintuitive:
expr1(expr2)
Here are our considerations:
-
The obvious alternative is to introduce a slicing method, ex.
expr1.slice(expr2)
especially that we already havelocalSlice
methods. -
Slicing is particularly useful on domains and arrays. Some prefer to write it with square brackets, as in
expr1[expr2]
, although Chapel treats it the same as parens.
Having to writeA.slice[x..y]
instead ofA[x..y]
can be seen as a step backwards. -
We could potentially support both the paren form and a method.
Although this goes against the principle that there should not be two ways of doing the same thing. -
Whatever we do, it should be consistent between ranges, domains, and arrays.
-
If expr1 is range and expr2 is an integer,
expr1(expr2)
should be a valid “element access” (by analogy to indexing into an array), perhaps meaningorderToIndex
#14884