<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 Dec 19, 2015, at 8:27 PM, Dennis Lysenko &lt;<a href="mailto:dennis.s.lysenko@gmail.com" class="">dennis.s.lysenko@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Dave, perhaps we could use "^" as an anchor point for the start index and $ as the anchor point for the end index? It's familiar to anyone who knows a bit of regex, and all vim users. My main worry would be ^ is already infix xor operator.</div></div></blockquote><div><br class=""></div>We could. &nbsp;</div><div><br class=""></div><div>Downsides:</div><div>• it's a needless additional sigil&nbsp;</div><div>• it requires a language extension to express x[^ + 3] unless we fake it with prefix operators ^- and ^+.</div><div><br class=""></div><div><br class=""></div><div><blockquote type="cite" class=""><div class=""><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Fri, Dec 18, 2015 at 5:43 PM Paul Ossenbruggen via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""></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" class="">I would like to avoid what you currently have to do for iterating a subcontainer.&nbsp;<div class=""><br class=""></div><div class="">for a in container[0..container.count-4] {</div><div class=""><span style="white-space:pre-wrap" class="">        </span>// do something.&nbsp;</div><div class="">}</div><div class=""><br class=""></div><div class="">The slicing syntax would certainly help in these common situations. Maybe there are easy ways that I am not aware of.&nbsp;</div></div><div style="word-wrap:break-word" class=""><div class=""><br class=""></div><div class="">- Paul</div></div><div style="word-wrap:break-word" class=""><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 18, 2015, at 2:39 PM, Dave Abrahams via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class=""><div class=""><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><blockquote type="cite" class=""><div class=""><br class="">On Dec 18, 2015, at 1:46 PM, Joe Groff via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class=""><div class=""><div style="font-family:AvenirNext-Regular;font-size:15px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><blockquote type="cite" class=""><div class=""><br class="">On Dec 18, 2015, at 4:42 AM, Amir Michail via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class=""><div class=""><div style="word-wrap:break-word" class="">Examples:<div class=""><br class=""></div><div class=""><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo" class="">&gt;&gt;&gt; l=[1,2,3,4,5]</div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo" class="">&gt;&gt;&gt; l[-1]</div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo" class="">5</div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo" class="">&gt;&gt;&gt; l[-2]</div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo" class="">4</div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo" class="">&gt;&gt;&gt; l[2:4]</div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo" class="">[3, 4]</div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo" class="">&gt;&gt;&gt; l[2:]</div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo" class="">[3, 4, 5]</div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo" class="">&gt;&gt;&gt; l[-2:]</div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo" class="">[4, 5]</div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo" class="">&gt;&gt;&gt; l[:3]</div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo" class="">[1, 2, 3]</div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo" class="">&gt;&gt;&gt; l[::2]</div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo" class="">[1, 3, 5]</div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo" class="">&gt;&gt;&gt; l[::]</div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo" class="">[1, 2, 3, 4, 5]</div></div></div></div></blockquote><br class=""></div><div style="font-family:AvenirNext-Regular;font-size:15px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="">Accepting negative indices is problematic for two reasons: it imposes runtime overhead in the index operation to check the sign of the index; also, it masks fencepost errors, since if you do foo[m-n] and n is accidentally greater than m, you'll quietly load the wrong element instead of trapping. I'd prefer something like D's `$-n` syntax for explicitly annotating end-relative indexes.</div></div></blockquote><br class=""></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" 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 style="font-family:AvenirNext-Regular" class="">&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></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><div style="font-family:AvenirNext-Regular" class=""><br class=""></div><div style="font-family:AvenirNext-Regular" class=""><font face="Menlo" class="">&nbsp; c[c.startIndex.advancedBy(3)] =&gt;<span style="white-space:pre-wrap" class="">        </span>c[$+3] &nbsp; &nbsp; &nbsp; &nbsp;// Python: c[3]</font></div><div style="font-family:AvenirNext-Regular" class=""><div class=""><font face="Menlo" class="">&nbsp; c[c.endIndex.advancedBy(-3)] =&gt;<span style="white-space:pre-wrap" class="">        </span>c[$-3] &nbsp; &nbsp; &nbsp; &nbsp;// Python: c[-3]</font></div><div class=""></div><div class=""><span style="font-family:Menlo" class="">&nbsp; c.dropFirst(3) &nbsp;=&gt;</span><span style="font-family:Menlo;white-space:pre-wrap" class="">                        </span><span style="font-family:Menlo" class="">c[$+3...] &nbsp; &nbsp; // Python: c[3:]</span></div></div><div style="font-family:AvenirNext-Regular" class=""><font face="Menlo" class="">&nbsp; c.dropLast(3) =&gt;<span style="white-space:pre-wrap" class="">                        </span>c[..&lt;$-3] &nbsp; &nbsp; // Python: c[:-3]</font></div><div style="font-family:AvenirNext-Regular" class=""><font face="Menlo" class="">&nbsp; c.prefix(3) =&gt;<span style="white-space:pre-wrap" class="">                        </span>c[..&lt;$+3] &nbsp; &nbsp; // Python: c[:3]</font></div><div style="font-family:AvenirNext-Regular" class=""><font face="Menlo" class="">&nbsp; c.suffix(3) =&gt;&nbsp;<span style="white-space:pre-wrap" class="">                        </span>c[$-3...] &nbsp; &nbsp; // Python: c[-3:]</font></div><div style="font-family:AvenirNext-Regular" class="">&nbsp; &nbsp;</div></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><span style="font-family:AvenirNext-Regular" class="">It even has the nice connotation that, “this might be a little more expen</span><font face="Menlo" class="">$</font><span style="font-family:AvenirNext-Regular" class="">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;</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing: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;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" 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.</div><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="">-Dave<div class=""><br class=""></div><br class=""></div><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=emrIhnP1hIf76Foxxv4NNJQX-2FWhcznESwKBSwD1MEwyj0iXgKJmkONj9Rbnwt3q2dEUDPmlaWgQO0ZpHBFxUxtruLEXt6cSO2nPi8zqkNon0c9o0Q5EsF2-2FQXAKvkmtBQyQYHq64ld1UumiHyAexfaduXkigo8nARwHpoJDbqPdMRb2UKj4RB-2FRz7fR34BiY0Rhn8B5-2BbU7da-2FqjAABF-2FKaF3FxfGW27qMZJYGv7o5I-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;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;min-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;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important" class=""><span class="">&nbsp;</span></span><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing: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;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing: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;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing: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;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank" 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;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing: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;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=8CZIdLciSFC-2BO5jF-2FiP8qN7dBFsgCUZ50wdTsolcRPex1NHvgVUPj30eqJZg2O-2BdgmN1nwDigHsC35SEyG0FPu8fkFgBn8QnwbSSx03OSw4-2FM69V-2BAQB-2FIweTGSIeu0r93FelAyiVcphQAXC63JR-2BYy159w0sGQ-2Bu7i8s8fC6TyUPyEOvPiI3lto92tQkZoHvIq9XEvU5rzAmsA2TmP30sQ5e5qELFgEGoG-2F9vBdTJc-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important" class="">
</div>
_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" target="_blank" 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/mailman/listinfo/swift-evolution</a><br class="">
</blockquote></div>
</div></blockquote></div><br class=""><div class="">
-Dave<div class=""><br class=""></div><br class="Apple-interchange-newline">

</div>
<br class=""></body></html>