<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="">Why not make the “forgiving” version the default? I mean, the majority of python-style composable slicing would be happening on arrays and array slices, for which there’s no performance overhead, and the forgiving version would seam to suit the “safe-by-default” philosophy. I’ve seen mistakes like this:<div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> ar = [<span style="font-variant-ligatures: no-common-ligatures; color: #312cdd" class="">1</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #312cdd" class="">2</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #312cdd" class="">3</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #312cdd" class="">4</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #312cdd" class="">5</span>]</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> arSlice = ar[<span style="font-variant-ligatures: no-common-ligatures; color: #312cdd" class="">2</span>..&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #312cdd" class="">5</span>]</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">arSlice[<span style="font-variant-ligatures: no-common-ligatures; color: #312cdd" class="">1</span>]</div></div><div class=""><br class=""></div><div class="">on a few occasions, for instance. I would think something like this:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> ar = [<span style="font-variant-ligatures: no-common-ligatures; color: #312cdd" class="">0</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #312cdd" class="">1</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #312cdd" class="">2</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #312cdd" class="">3</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #312cdd" class="">4</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #312cdd" class="">5</span>]</div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> arSlice = <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">ar</span>[<span style="font-variant-ligatures: no-common-ligatures; color: #312cdd" class="">2</span>...] <span style="font-variant-ligatures: no-common-ligatures; color: #4f8f00" class="">// [3, 4, 5]</span></div><div style="margin: 0px; line-height: normal; color: rgb(79, 143, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">arSlice</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">[..&lt;</span><span style="font-variant-ligatures: no-common-ligatures; color: #312cdd" class="">3</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">] </span>// [2, 3, 4]</div><div style="margin: 0px; line-height: normal; color: rgb(79, 143, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">arSlice</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">[...</span><span style="font-variant-ligatures: no-common-ligatures; color: #312cdd" class="">3</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">] </span>// [2, 3, 4, 5]</div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">arSlice</span>[direct: <span style="font-variant-ligatures: no-common-ligatures; color: #312cdd" class="">2</span>] <span style="font-variant-ligatures: no-common-ligatures; color: #4f8f00" class="">// 2</span></div><div style="margin: 0px; line-height: normal; color: rgb(79, 129, 135);" class="">arSlice<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">[</span><span style="font-variant-ligatures: no-common-ligatures; color: #312cdd" class="">0</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">] </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8f00" class="">// 2</span></div></div></div><div class=""><br class=""></div><div class="">Would be what was expected from most programmers learning Swift, while leaving the unforgiving option open to those who need it.</div><div class=""><br class=""></div><div class=""><div class=""><div class=""><div><blockquote type="cite" class=""><div class="">On 22 Dec 2015, at 03:29, Dave Abrahams 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 style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">On Dec 21, 2015, at 1:51 PM, Kevin Ballard &lt;<a href="mailto:kevin@sb.org" class="">kevin@sb.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><div class="">On Mon, Dec 21, 2015, at 11:56 AM, Dave Abrahams wrote:<br class=""></div><blockquote type="cite" class=""><div class="">&nbsp;</div><div class=""><blockquote type="cite" class=""><div class="">On Dec 19, 2015, at 8:52 PM, Kevin Ballard via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""></div><div class="">&nbsp;</div><div class=""><div class=""><div class="">On Fri, Dec 18, 2015, at 02:39 PM, Dave Abrahams via swift-evolution wrote:<br class=""></div><blockquote type="cite" class=""><div class="">&nbsp;</div><div class="">Yes, we already have facilities to do most of what Python can do here, but one major problem IMO is that the “language” of slicing is so non-uniform: we have [a..&lt;b], dropFirst, dropLast, prefix, and suffix. &nbsp;Introducing “$” for this purpose could make it all hang together<span class="font" style="font-family: AvenirNext-Regular;">&nbsp;and also eliminate the “why does it have to be so hard to look at the 2nd character of a string?!” problem. &nbsp;That is, use the identifier “$” (yes, that’s an identifier in Swift) to denote the beginning-or-end of a collection. &nbsp;Thus,</span><br class=""></div><div class=""><div class="" style="font-family: AvenirNext-Regular;">&nbsp;</div><div class="" style="font-family: AvenirNext-Regular;"><span class="font" style="font-family: Menlo;">&nbsp; c[c.startIndex.advancedBy(3)] =&gt;<span class="" style="white-space: pre;"></span>c[$+3] &nbsp; &nbsp; &nbsp; &nbsp;// Python: c[3]</span><br class=""></div><div class="" style="font-family: AvenirNext-Regular;"><div class=""><span class="font" style="font-family: Menlo;">&nbsp; c[c.endIndex.advancedBy(-3)] =&gt;<span class="" style="white-space: pre;"></span>c[$-3] &nbsp; &nbsp; &nbsp; &nbsp;// Python: c[-3]</span><br class=""></div><div class="">&nbsp;</div><div class=""><span class="font" style="font-family: Menlo;">&nbsp; c.dropFirst(3) &nbsp;=&gt;</span><span class="font" style="font-family: Menlo;"></span><span class="font" style="font-family: Menlo;">c[$+3...] &nbsp; &nbsp; // Python: c[3:]</span><br class=""></div></div><div class="" style="font-family: AvenirNext-Regular;"><span class="font" style="font-family: Menlo;">&nbsp; c.dropLast(3) =&gt;<span class="" style="white-space: pre;"></span>c[..&lt;$-3] &nbsp; &nbsp; // Python: c[:-3]</span><br class=""></div><div class="" style="font-family: AvenirNext-Regular;"><span class="font" style="font-family: Menlo;">&nbsp; c.prefix(3) =&gt;<span class="" style="white-space: pre;"></span>c[..&lt;$+3] &nbsp; &nbsp; // Python: c[:3]</span><br class=""></div><div class="" style="font-family: AvenirNext-Regular;"><span class="font" style="font-family: Menlo;">&nbsp; c.suffix(3) =&gt;&nbsp;<span class="" style="white-space: pre;"></span>c[$-3...] &nbsp; &nbsp; // Python: c[-3:]</span><br class=""></div><div class="" style="font-family: AvenirNext-Regular;">&nbsp;</div></div><div class=""><span class="font" style="font-family: AvenirNext-Regular;">It even has the nice connotation that, “this might be a little more expen</span><span class="font" style="font-family: Menlo;">$</span><span class="font" style="font-family: AvenirNext-Regular;">ive than plain indexing” (which it might, for non-random-access collections). &nbsp;</span>I think the syntax is still a bit heavy, not least because of “..&lt;“ and “...”, but the direction has potential.&nbsp;<br class=""></div><div class="">&nbsp;</div><div class="">&nbsp;I haven’t had the time to really experiment with a design like this; the community might be able to help by prototyping and using some alternatives. &nbsp;You can do all of this outside the standard library with extensions.<br class=""></div></blockquote><div class="">&nbsp;</div><div class="">Interesting idea.<br class=""></div><div class="">&nbsp;</div><div class="">One downside is it masks potentially O(N) operations (ForwardIndex.advancedBy()) behind the + operator, which is typically assumed to be an O(1) operation.<br class=""></div></div></div></blockquote><div class="">&nbsp;</div><div class="">Yeah, but the “$” is sufficiently unusual that it doesn’t bother me too much.<br class=""></div><div class="">&nbsp;</div><blockquote type="cite" class=""><div class=""><div class=""><div class="">Alos, the $+3 syntax suggests that it requires there to be at least 3 elements in the sequence, but prefix()/suffix()/dropFirst/etc. all take maximum counts, so they operate on sequences of fewer elements.<br class=""></div></div></div></blockquote><div class="">&nbsp;</div><div class="">For indexing, $+3 would make that requirement. &nbsp;For slicing, it wouldn’t. &nbsp;I’m not sure why you say something about the<span class="Apple-converted-space">&nbsp;</span><u class="">syntax</u><span class="Apple-converted-space">&nbsp;</span>suggests exceeding bounds would be an error.<br class=""></div></div></blockquote><div class="">&nbsp;</div><div class="">Because there's no precedent for + behaving like a saturating addition, not in Swift and not, to my knowledge, anywhere else either. The closest example that comes to mind is floating-point numbers eventually ending up at Infinity, but that's not really saturating addition, that's just a consequence of Infinity + anything == Infinity. Nor do I think we should be establishing precedent of using + for saturating addition, because that would be surprising to people.</div></div></div></blockquote><div class=""><br class=""></div>To call this “saturating addition” is an…interesting…interpretation. &nbsp;I don’t view it that way at all. &nbsp;The “saturation,” if there is any, happens as part of subscripting. &nbsp;You don’t even know what the “saturation limit” is until you couple the range expression with the collection. &nbsp;</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">In my view, the addition is part of an EDSL that represents a notional position offset from the start or end, then the subscript operation forgivingly trims these offsets as needed.</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""><blockquote type="cite" class=""><div class=""><div class=""><div class="">Additionally, I don't think adding a $ to an array slice expression should result in a behavioral difference, e.g. array[3..&lt;array.endIndex] and array[$+3..&lt;$] should behave the same<br class=""></div></div></div></blockquote><div class=""><br class=""></div><div class="">I see your point, but don’t (necessarily) agree with you there. &nbsp;“$” here is used as an indicator of several of things, including not-necessarily-O(1) and forgiving slicing. &nbsp;We could introduce a label just to handle that:</div><div class=""><br class=""></div><div class="">&nbsp;array[forgivingAndNotO1: $+3..&lt;$] &nbsp;</div><div class=""><br class=""></div><div class="">but it doesn’t look like a win to me.</div><div class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div class="">&nbsp;</div><blockquote type="cite" class=""><div class=""><blockquote type="cite" class=""><div class=""><div class="">There's also some confusion with using $ for both start and end. What if I say c[$..&lt;$]? We'd have to infer from position that the first $ is the start and the second $ is the end, but then what about c[$+n..&lt;$+m]? We can't treat the usage of + as meaning "from start" because the argument might be negative. And if we use the overall sign of the operation/argument together, then the expression `$+n` could mean from start or from end, which comes right back to the problem with Python syntax.<br class=""></div></div></blockquote><div class="">&nbsp;</div><div class="">There’s a problem with Python syntax? &nbsp;I’m guessing you mean that c[a:b] can have very different interpretations depending on whether a and b are positive or negative?<br class=""></div></div></blockquote><div class="">&nbsp;</div><div class="">Exactly.</div><div class="">&nbsp;</div><blockquote type="cite" class=""><div class=""><div class="">First of all, I should say: that doesn’t really bother me. &nbsp;The 99.9% use case for this operation uses literal constants for the offsets, and I haven’t heard of it causing confusion for Python programmers. &nbsp;That said, if we wanted to address it, we could easily require n and m above to be literals, rather than Ints (which incidentally guarantees it’s an O(1) operation). &nbsp;That has upsides and downsides of course.<br class=""></div></div></blockquote><div class="">&nbsp;</div><div class="">I don't think we should add this feature in any form if it only supports literals.<br class=""></div><div class="">&nbsp;&nbsp;</div><blockquote type="cite" class=""><div class=""><blockquote type="cite" class=""><div class=""><div class="">I think Jacob's idea has some promise though:<br class=""></div><div class="">&nbsp;</div><div class="">c[c.startIndex.advancedBy(3)] =&gt; c[fromStart: 3]<br class=""></div><div class="">c[c.endIndex.advancedBy(-3)] =&gt; c[fromEnd: 3]<br class=""></div></div></blockquote><div class="">&nbsp;</div><blockquote type="cite" class=""><div class=""><div class="">But naming the slice operations is a little trickier. We could actually just go ahead and re-use the existing method names for those:<br class=""></div><div class="">&nbsp;</div><div class="">c.dropFirst(3) =&gt; c[dropFirst: 3]<br class=""></div><div class="">c.dropLast(3) =&gt; c[dropLast: 3]<br class=""></div><div class="">c.prefix(3) =&gt; c[prefix: 3]<br class=""></div><div class="">c.suffix(3) =&gt; c[suffix: 3]<br class=""></div><div class="">&nbsp;</div><div class="">That's not so compelling, since we already have the methods, but I suppose it makes sense if you want to try and make all slice-producing methods use subscript syntax (which I have mixed feelings about).<br class=""></div></div></blockquote><div class="">&nbsp;</div><div class="">Once we get efficient in-place slice mutation (via slice addressors), it becomes a lot more compelling, IMO. &nbsp;But I still don’t find the naming terribly clear, and I don’t love that one needs to combine two subscript operations in order to drop the first and last element or take just elements 3..&lt;5.<br class=""></div></div></blockquote><div class="">&nbsp;</div><div class="">You can always add more overloads, such as<br class=""></div><div class="">&nbsp;</div><div class="">c[dropFirst: 3, dropLast: 5]<br class=""></div><div class="">&nbsp;</div><div class="">but I admit that there's a bunch of combinations here that would need to be added.<br class=""></div><div class=""><br class=""></div></div></blockquote><div class=""><br class=""></div>My point is that we have an English language soup that doesn’t compose naturally. &nbsp;Slicing in Python is much more elegant and composes well. &nbsp;If we didn’t currently have 6 separate methods (7 including subscript for index-based slicing) for handling this, that need to be separately documented and understood, I wouldn’t be so eager to replace the words with an EDSL, but in this case IMO it is an overall simplification.</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""><blockquote type="cite" class=""><div class=""><div class="">My concern over trying to make it easier to take elements 3..&lt;5 is that incrementing indexes is verbose for a reason, and adding a feature that makes it really easy to index into any collection by using integers is a bad idea as it will hide O(N) operations behind code that looks like O(1). And hiding these operations makes it really easy to accidentally turn an O(N) algorithm into an O(N^2) algorithm.</div></div></blockquote><div class=""><br class=""></div><div class="">As I’ve said, I consider the presence of “$” to be enough of an indicator that something co$tly is happening, though I’m open to other ways of indicating it. &nbsp;I’m trying to strike a balance between “rigorous” and “easy to use,” here. &nbsp;Remember that Swift has to work in playgrounds and for beginning programmers, too. &nbsp;I am likewise unsatisfied with the (lack of) ease-of-use of String as well (e.g. for lexing and parsing tasks), and have made improving it a priority for Swift 3. &nbsp;I view fixing the slicing interface as part of that job.</div><div class=""><br class=""></div></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class=""><blockquote type="cite" class=""><div class=""><div class="">Even if we need separate symbols for “start” and “end” (e.g. using “$” for both might just be too confusing for people in the end, even if it works otherwise), I still think a generalized form that allows ranges to be used everywhere for slicing is going to be much easier to understand than this hodgepodge of words we use today.<br class=""></div></div></blockquote><div class="">&nbsp;</div><div class="">I'm tempted to say that if we do this, we should use two different sigils, and more importantly we should not use + and - but instead use methods on the sigils like advancedBy(), as if the sigils were literally placeholders for the start/end index. That way we won't write code that looks O(1) when it's not. For example:<br class=""></div><div class="">&nbsp;</div><div class="">col[^.advancedBy(3)..&lt;$]<br class=""></div><div class="">&nbsp;</div><div class="">Although we'd need to revisit the names a little, because $.advancedBy(-3) is a bit odd when we know that $ can't ever take a non-negative number for that.<br class=""></div><div class="">&nbsp;</div><div class="">Or maybe we should just use $ instead as a token that means "the collection being indexed", so you'd actually say something like<br class=""></div><div class="">&nbsp;</div><div class="">col[$.startIndex.advancedBy(3)..&lt;$.startIndex.advancedBy(5)]</div></div></blockquote><div class=""><br class=""></div>I really like that direction, but I don’t think it does enough to solve the ease-of-use problem; I still think the result looks and feels horrible compared to Python for the constituencies mentioned above. &nbsp;</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">I briefly implemented this syntax, that was intended to suggest repeated incrementation:</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><font face="Menlo" class=""><br class=""></font><div class=""><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>col.startIndex++3 //&nbsp;</font><span class="" style="font-family: Menlo;">col.startIndex.advancedBy(3)</span></div></div></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">I don’t think that is viable, especially now that we’ve dropped “++” and “--“. But this syntax&nbsp;</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class=""><div class=""><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>col[$.start</font><span class="" style="font-family: Menlo;">⛄️</span><font face="Menlo" class="">3..&lt;$.start⛄️5]</font></div><div class=""><span class="" style="font-family: Menlo;"><br class=""></span></div></div></div></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">begins to be interesting for some definition of&nbsp;<span class="" style="font-family: Menlo;">⛄️</span>.</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class=""><div class="">This solves the problem of subscripting a collection without having to store it in a local variable, without discarding any of the intentional index overhead. Of course, if the goal is to make index operations more concise this doesn't really help much, but my argument here is that it's hard to cut down on the verbosity without hiding O(N) operations.</div></div></blockquote><div class=""><br class=""></div>That ship has already sailed somewhat, because e.g. every Collection has to have a count property, which can be O(N). &nbsp;But I still like to uphold it where possible. &nbsp;I just don’t think the combination of “+” and “$” necessarily has such a strong O(1) connotation… especially because the precedent for seeing those symbols together is regexps.</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""><blockquote type="cite" class=""><div class=""><div class="">&nbsp;</div><div class="">-Kevin Ballard</div><div class="">&nbsp;</div><blockquote type="cite" class=""><div class=""><blockquote type="cite" class=""><div class=""><div class="">But the [fromStart:] and [fromEnd:] subscripts seem useful.<br class=""></div></div></blockquote><div class="">Yeah… I really want a unified solution that covers slicing as well as offset indexing.<br class=""></div><div class="">&nbsp;</div></div><div class=""><div class="">-Dave<br class=""></div><div class="">&nbsp;</div></div></blockquote><div class="">&nbsp;</div></div></blockquote></div><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">-Dave<div class=""><br class=""></div><br class="Apple-interchange-newline"></div><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=Lo8TP3b1oIn3yQXUt9zA1UCQfR-2BMBCuqnubTuDg47-2B03vpcFwoffg7ti-2FpuTP0DjBpIqBq3m-2BsAD2A1mPXBkrY8ynd6eW-2BzzVzIYTSzZ0mUopmZ5Qslwx-2Bmyq99qbXQHYHsuOOzqK-2FB1gVbQ0Pczq6F4Yuiw3C5LpvG07c1AUWMukLbMjU6qsRQM-2FGAnn0-2FM1uCgzxoFuXtUVspSvpTcPoAydqXqCWoy1G9dPP-2F3YHQ-3D" alt="" width="1" height="1" border="0" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class=""><span class="Apple-converted-space">&nbsp;</span></span><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">swift-evolution mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:swift-evolution@swift.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">swift-evolution@swift.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></div></div></div></body></html>