<div dir="ltr">On Tue, Jan 31, 2017 at 5:58 PM, Matthew Johnson <span dir="ltr">&lt;<a href="mailto:matthew@anandabits.com" target="_blank">matthew@anandabits.com</a>&gt;</span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><span class=""><blockquote type="cite"><div>On Jan 31, 2017, at 5:20 PM, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>&gt; wrote:</div><br class="m_5497944995467087879Apple-interchange-newline"><div><div dir="ltr">On Tue, Jan 31, 2017 at 5:04 PM, Matthew Johnson <span dir="ltr">&lt;<a href="mailto:matthew@anandabits.com" target="_blank">matthew@anandabits.com</a>&gt;</span> wrote:<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 style="word-wrap:break-word"><div><span class="m_5497944995467087879gmail-"><div><br></div></span><div>I think it’s fair to say that we get to decide on the semantics of postfix `…`.  “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).  </div></div></div></blockquote><div><br></div><div>&quot;All the rest&quot; is by itself insufficient so far as semantics: all the rest _of what_? Supposing that our supplied lower bound is an integer, it must be all the rest of the integers. It cannot be all the rest of whatever, where whatever might be a collection that you try to subset with `0...`. (Recall that collections move indices, but indices know nothing about the collections.) It would be exceeding fuzzy for postfix `...` to mean &quot;all the rest of whatever I want it to mean&quot;--that, almost tautologically, has no semantics at all.</div></div></div></div></div></blockquote><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></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 style="word-wrap:break-word"><div><div></div><div>Under the latter semantics, a `for i in 0…` loop would terminate after reaching Int.max.  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></div></blockquote><div><br></div><div>OK, I&#39;m borderline fine with `0... == 0...Int.max`. It at least provides some semantics (i.e., we&#39;re saying `...` refers to all the rest of the values representable by the type used for the lower bound) [**]. But Jaden&#39;s point still stands, since it would only be consistent if `for i in arr[0...]` then traps after `arr.count` just like `for i in arr[0...Int.max]` would do. Otherwise, we really are fudging the semantics.</div></div></div></div></div></blockquote><div><br></div></span><div>If we really want to be honest about the information a value produced using postfix `…` carries, it is a partial range with only the lower bound specified.  This allows us to assign meaning to that partial range using additional context: </div><div><br></div><div>* When it is possible to increment Bound directly could be interpreted as an (near?) infinite sequence that either terminates or traps when it reaches an unrepresentable value.</div><div>* When Bound is an index and the partial range is used as a subscript argument it can be interpreted to mean “to the end of the collection”.</div></div></div></blockquote><div><br></div><div>These are two very different semantics. One says, `i...` is a range with no upper bound; the other says, `i...` is a lower bound of something. The objection is twofold. In the first place, those shouldn&#39;t be spelled the same way. In the second place, the &quot;lower bound of something&quot; is already adequately accommodated by using, well, the actual lower bound. Well, also, the &quot;range with no upper bound&quot; isn&#39;t very useful in practice, especially if the only compelling use case is one for replacing an existing API that, well, there is no consensus yet to replace.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div>This still leaves us with an out of bounds crash in David’s example that iterates over a partial range.  This is an artifact of `Array` using Int as it’s `Index` rather than an opaque type that does not allow users to increment it directly rather than using a collection.  </div><div><br></div><div>Is the problem in David’s example really that different than the ability to directly index an array with any `Int` we want?  It’s not the kind of thing that developers would do frequently.  The first time they try it they will get a crash and will learn not to do it again.</div><div><br></div><div>I’m not necessarily arguing one way or the other.  I’m simply pointing out that “partial range” is a perfectly reasonable semantics to consider.</div><span class=""><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>[**] It is not perfectly consistent semantically because, as was discussed in threads about our numeric protocols, our integer types are supposed to model all integers, not just the ones that happen to be representable. Our model is imperfect because not all integers fit into finite memory, but that&#39;s a modeling artifact and not intentional semantics. IIUC, it would be otherwise difficult to give a good accounting of, say, the semantics of addition if arithmetic overflow were an intentional part of the semantics and not an artifact.</div></div></div></div></div></blockquote><div><br></div></span><div>I haven’t followed all of the details of the numeric protocol discussions.  With this in mind, I agree with your proposed semantics of trapping after `Int.max` as it sounds more consistent with this intent.</div><span class=""><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></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 style="word-wrap:break-word"><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`.  IMO, he makes a pretty strong case for this.</div><span class="m_5497944995467087879gmail-"><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div><br></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"><div>- Dave Sweeris </div></div><br>______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div></div>
______________________________<wbr>_________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-evolution</a><br></div></blockquote></span></div><br></div></blockquote></div><br></div></div>
</div></blockquote></span></div><br></div></blockquote></div><br></div></div>