<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 31, 2017, at 4:04 PM, Xiaodi Wu via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">On Tue, Jan 31, 2017 at 3:36 PM, David Sweeris via swift-evolution <span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span> wrote:<br class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="auto" class=""><span class="gmail-"><div class=""><br class=""></div><div class="">On Jan 31, 2017, at 11:32, Jaden Geller via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><span class="">I think that is perfectly reasonable, but then it seems weird to be able to iterate over it (with no upper bound) independently of a collection). It would surprise me if</span><br class=""><span class="">```</span><br class=""><span class="">for x in arr[arr.startIndex…] { print(x) }</span><br class=""><span class="">```</span><br class=""><span class="">yielded different results than</span><br class=""><span class="">```</span><br class=""><span class="">for i in arr.startIndex… { print(arr[i]) } // CRASH</span><br class=""><span class="">```</span><br class=""><span class="">which it does under this model.</span><br class=""></div></blockquote><br class=""></span><div class="">(I <i class="">think</i> this how it works... semantically, anyway) Since the upper bound isn't specified, it's inferred from the context.</div><div class=""><br class=""></div><div class="">In the first case, the context is as an index into an array, so the upper bound is inferred to be the last valid index.</div><div class=""><br class=""></div><div class="">In the second case, there is no context, so it goes to Int.max. Then, <i class="">after</i> the "wrong" context has been established, you try to index an array with numbers from the too-large range.</div><div class=""><br class=""></div><div class="">Semantically speaking, they're pretty different operations. Why is it surprising that they have different results?</div></div></blockquote><div class=""><br class=""></div><div class="">I must say, I was originally rather fond of `0...` as a spelling, but IMO, Jaden and others have pointed out a real semantic issue.</div><div class=""><br class=""></div><div class="">A range is, to put it simply, the "stuff" between two end points. A "range with no upper bound" _has to be_ one that continues forever.</div></div></div></div></div></blockquote><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class="">The upper bound _must_ be infinity. What Dave Abrahams has described does not have the semantics of a range with no upper bound. He's describing a standalone lower bound with no "stuff." It stands to reason that such a type should not be a sequence at all. But we already use particular types for upper and lower bounds that aren't sequences, and they're plain numeric types. Therefore I'd conclude that `arr[upTo: i]` is the most consistent spelling. It also yields the sensible result that `arr[from: i][upTo: j] == arr[upTo: j][from: i] == arr[i..&lt;j]`.</div><div class=""><br class=""></div><div class="">If `0...` is to have the semantics of a range with no upper bound, I would expect `for i in 0...` to be an infinite loop, equivalent to `for i in stride(from: 0, through: Int.max, by: 1)` for Int.max+1 iterations and then trapping. Which is, well, silly. I'm coming around to thinking that `0...` is a sexy notation for something we don't need and a poor notation for something that's more cleanly expressed by plain numbers.</div></div></div></div></div></blockquote><div><br class=""></div><div><br class=""></div><div>I think it’s fair to say that we get to decide on the semantics of postfix `…`. &nbsp;“a range with no upper bound” is very reasonable, but wouldn’t another reasonable semantics be “all the rest”, meaning that there *is* an upper bound (the greatest possible value). &nbsp;</div><div><br class=""></div><div>Under the latter semantics, a `for i in 0…` loop would terminate after reaching Int.max. &nbsp;This is probably not what the user intended and would still crash when used in David’s example, but it’s worth considering.</div><div><br class=""></div><div>I’m not sure if you read Ben’s post regarding `enumerated` or not, but he gave the example of `zip(0…, sequence)` as a more general replacement for `enumerated`. &nbsp;IMO, he makes a pretty strong case for this.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""><br class=""></div><div class=""><br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="auto" class=""><div class="">- Dave Sweeris&nbsp;</div></div><br class="">______________________________<wbr class="">_________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/<wbr class="">mailman/listinfo/swift-<wbr class="">evolution</a><br class="">
<br class=""></blockquote></div><br class=""></div></div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>