You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
start..end// corresponds to new Range(index1, idnex
start.. // corresponds to start..^0
..end// corresponds to 0..end
.. // corresponds to 0..^0
With list patterns (coming soon):
varxis[p1, .. var rem,p2,p3];// here `..` effectively corresponds to `x[1..^2]`
With collection expressions (hopefully coming in a future release):
varx=[e1,e2, .. c1,e3,e4, .. c2];// here .. is used to 'spread' the elements of c1/c2 into the final result.
This all works decently well, and allows .. to generally represent the idea of something rangish. e.g. you can squint and see how in list patterns that .. collects a sub-range of the the original object, just with indices determined by the patterns around it. For collection expressions it kind of says "grab the whole range of a collection and add all the items in that range into the final collection".
However, this raises some syntactic concerns.
First, while there is no syntactic ambiguity with patterns today, there may be in the future. For example, by our 'correspondence principle' we might want to have a range pattern in the future which might look like this: if (x is (var p1 .. var p2)) { ... } to grab out the indices from a range (and potentially have deeper patterns for those parts).
Second, for expressions this is purely syntactically ambiguous. ..c2 has meaning today as a range-expression. To have it now mean spread-expression would mean something very different based on context. This introduces papercuts such as forcing users to parenthesize if they actually want a collection of ranges. e.g.: [.., e1.., (..e2)].
Do we want to go forward with reusing .. for all these meanings? Or should we consider a path that avoids that?
The text was updated successfully, but these errors were encountered:
Extracting the indices from a range and having deeper patterns for those parts could be achieved using a range Deconstruct method: if (x is (var p1, var p2)). It wouldn't correspond syntactically but it would be consistent with what you'd see for types like Point.
For context, we use
..
in teh following fashions.For range expressions:
With list patterns (coming soon):
With collection expressions (hopefully coming in a future release):
This all works decently well, and allows
..
to generally represent the idea of somethingrangish
. e.g. you can squint and see how in list patterns that..
collects a sub-range of the the original object, just with indices determined by the patterns around it. For collection expressions it kind of says "grab the whole range of a collection and add all the items in that range into the final collection".However, this raises some syntactic concerns.
First, while there is no syntactic ambiguity with patterns today, there may be in the future. For example, by our 'correspondence principle' we might want to have a
range pattern
in the future which might look like this:if (x is (var p1 .. var p2)) { ... }
to grab out the indices from a range (and potentially have deeper patterns for those parts).Second, for expressions this is purely syntactically ambiguous.
..c2
has meaning today as arange-expression
. To have it now meanspread-expression
would mean something very different based on context. This introduces papercuts such as forcing users to parenthesize if they actually want a collection of ranges. e.g.:[.., e1.., (..e2)]
.Do we want to go forward with reusing
..
for all these meanings? Or should we consider a path that avoids that?The text was updated successfully, but these errors were encountered: