<div dir="ltr">I am also +1.<div><div><br></div><div><br></div><div>On Wed, Feb 1, 2017 at 9:29 AM, Matthew Johnson via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</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"><br>I’m still curious how postfix `…` would impact our options for variadic generics and tuple unpacking in the future.</blockquote><div><br></div><div><br></div><div>Somebody who happens to have originally created Swift addressed this point last week:</div><div><br></div><div><br></div><div>On Wed, Jan 25, 2017 at 8:49 PM, Chris Lattner via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</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"><div style="word-wrap:break-word"><div><br class="gmail-Apple-interchange-newline">In any case, it seems like an obviously good tradeoff to make the syntax for variadic generics more complicated if it makes one sided ranges more beautiful.</div><div><br></div><div>-Chris</div></div></blockquote></div><div><br></div><div><br></div><div>I think we should start a new thread for the discussion of incomplete ranges though.<br></div><div><br></div><div>Nevin</div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Feb 1, 2017 at 9:29 AM, Matthew Johnson via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</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"><br>
&gt; On Feb 1, 2017, at 6:58 AM, Brent Royal-Gordon via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br>
&gt;<br>
&gt;&gt; On Jan 31, 2017, at 2:04 PM, Xiaodi Wu via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Therefore I&#39;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]`.<br>
&gt;<br>
&gt; There&#39;s a lot I dislike about `subscript(upTo/through/from:)<wbr>`:<br>
&gt;<br>
&gt; 1. We have not previously been very satisfied with how understandable these labels are—for instance, we fiddled around with them a lot when we were looking at `stride(from:to/through:by:)` in Swift 3, and eventually settled on the originals because we couldn&#39;t find anything better. I don&#39;t think entrenching them further makes very much sense.<br>
&gt;<br>
&gt; 2. The fact that you *can* write `arr[from: i][upTo: j]`, and that this is equivalent to both `arr[upTo: j][from: i]` and `arr[i..&lt;j]`, seems a bit weird. We aren&#39;t typically in the habit of providing redundant APIs like this.<br>
&gt;<br>
&gt; 3. Neither Stdlib nor the Apple frameworks currently contain *any* labeled subscripts, so this design would be unprecedented in the core language.<br>
&gt;<br>
&gt; 4. After a new programmer learns about subscripting with two-sided ranges, removing one of the bounds is a straightforward extension of what they already know. The argument label solution is more ad-hoc.<br>
&gt;<br>
&gt; 5. The argument label solution solves the immediate problem, but doesn&#39;t give us anything else.<br>
&gt;<br>
&gt; To understand what I mean by #5, consider the implementation. The plan is to introduce a `RangeExpression` protocol:<br>
&gt;<br>
&gt;       protocol RangeExpression {<br>
&gt;               associatedtype Bound: Comparable<br>
&gt;               func relative&lt;C: Collection(to collection: C) where C.Index == Bound -&gt; Range&lt;Bound&gt;<br>
&gt;       }<br>
&gt;<br>
&gt; And then reduce the many manually-generated variants of `subscript(_: Range&lt;Index&gt;)` in `Collection` to just two:<br>
&gt;<br>
&gt;       protocol Collection {<br>
&gt;               ...<br>
&gt;               subscript(bounds: Range&lt;Index&gt;) -&gt; SubSequence { get }<br>
&gt;               ...<br>
&gt;       }<br>
&gt;<br>
&gt;       extension Collection {<br>
&gt;               ...<br>
&gt;               subscript&lt;Bounds: RangeExpression&gt;(bounds: Bounds) where Bounds.Bound == Index -&gt; SubSequence {<br>
&gt;                       return self[bounds.relative(to: self)]<br>
&gt;               }<br>
&gt;               ...<br>
&gt;       }<br>
&gt;<br>
&gt; This design would automatically, source-compatibly, handle several different existing types you can slice with:<br>
&gt;<br>
&gt; * ClosedRange<br>
&gt; * CountableRange<br>
&gt; * CountableClosedRange<br>
&gt;<br>
&gt; Plus the new types associated with incomplete ranges:<br>
&gt;<br>
&gt; * IncompleteRange<br>
&gt; * IncompleteClosedRange<br>
&gt;<br>
&gt; Plus anything else we, or users, might want to add. For instance, I have a prototype built on `RangeExpression` which lets you write things like:<br>
&gt;<br>
&gt;       myString[.startIndex + 1 ..&lt; .endIndex - 1]<br>
&gt;<br>
&gt; This strikes me as a pretty cool thing that some people might want.<br>
&gt;<br>
&gt; Similarly, IncompleteRange and IncompleteClosedRange can most likely be put to other uses. They could easily fill a gap in `switch` statements, which don&#39;t have a good way to express open-ended comparisons except with a `where` clause. As some have mentioned, when applied to a `Strideable` type they *could* be treated as infinite sequences, although it&#39;s not clear if we really want to do that. And, you know, sometimes you really *do* have a case where one or both bounds of a range may be missing in some cases; incomplete ranges are a built-in, batteries-included way to model that.<br>
&gt;<br>
&gt; To put it simply, slicing with incomplete ranges gives us several valuable tools we can apply to other problems. Labeled subscripts, on the other hand, are just another weird little thing that you have to memorize, and probably won’t.<br>
<br>
+1 in general.  But I’m still curious how postfix `…` would impact our options for variadic generics and tuple unpacking in the future.<br>
<br>
&gt;<br>
&gt; --<br>
&gt; Brent Royal-Gordon<br>
&gt; Architechies<br>
&gt;<br>
&gt; ______________________________<wbr>_________________<br>
&gt; swift-evolution mailing list<br>
&gt; <a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
&gt; <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>
______________________________<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>
</blockquote></div><br></div></div></div></div>