<div dir="ltr"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Are there contexts in which we would want i... and i..< to do different things?</blockquote><div><br></div><div>I posit that in the context of incomplete ranges, we always want “i...” to mean “greater than or equal to i”, and we do not want “i..<” to mean anything.</div><div><br></div><div>We may, however, want something like “i<..” to mean “strictly greater than i”, though I’m not sure how it should be spelled.</div><div><br></div><div>Nevin</div><div><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jan 30, 2017 at 12:31 PM, Nate Cook via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-"><br>
> On Jan 30, 2017, at 8:51 AM, Thorsten Seitz via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>
><br>
>> Am 23.01.2017 um 02:14 schrieb James Froggatt via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>:<br>
>><br>
>> Could we add subscript labels to the list of options? While keeping the range syntax is appealing, I'm concerned it may cause confusion if the operators are used out of context.<br>
><br>
> Good point!<br>
><br>
>> The wording is up for debate, but something like this should be a fair alternative:<br>
>> items[from: i]<br>
>> items[upTo: i]<br>
><br>
> For me that's at least as readable as the range syntax.<br>
><br>
>><br>
>> Sorry if this has been covered elsewhere (can't find the answer in this thread), but my first questions on discovering these operators (my source of confusion) would be what happens if I try the following:<br>
>> let partialRange = 0..< //is this an infinite range?<br>
>> let x = items[partialRange] //shouldn't this cause an out of bounds error?<br>
><br>
> Good point! Probably this shouldn't be allowed, making the literal range syntax with open ends tied into the subscript which is a bit confusing indeed.<br>
<br>
</span>`partialRange` here is an incomplete range, not an infinite one. When you use an incomplete range to subscript a collection, the collection "completes" it by filling in the start or end index as required. You can see more about the details of incomplete ranges in this proposal: <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0132-sequence-end-ops.md" rel="noreferrer" target="_blank">https://github.com/apple/<wbr>swift-evolution/blob/master/<wbr>proposals/0132-sequence-end-<wbr>ops.md</a><br>
<br>
One other aspect of incomplete ranges that I haven't seen discussed (though I may have missed it) is how they work inpattern matching. It would be nice to use incomplete ranges in switch statements, so that instead of:<br>
<br>
switch x {<br>
case let y where y < 0: print("< 0")<br>
case 0...10: print("0-10")<br>
case let y where y > 10: print("> 10")<br>
default: print("wat")<br>
}<br>
<br>
we could write:<br>
<br>
switch x {<br>
case ..<0: print("< 0")<br>
case 0...10: print("0-10")<br>
case 10...: print("> 10")<br>
default: print("wat")<br>
}<br>
<br>
To me, that implies that we'll want a postfix ... operator to exist, though I agree it's not clear what it should do in a subscript. Are there contexts in which we would want i... and i..< to do different things?<br>
<br>
Nate<br>
<div class="gmail-HOEnZb"><div class="gmail-h5"><br>
______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
</div></div></blockquote></div><br></div></div></div>