<div dir="ltr">Or perhaps some subscripts with parameter labels, like<div><br></div><div>extension Array {</div><div>    subscript(fromEnd distance: Int) -&gt; Element {</div><div>        return self[endIndex - distance]</div><div>    }</div><div>}</div><div><br></div><div>[0, 1, 2][fromEnd: 1] // returns 2</div><div class="gmail_extra"><br clear="all"><div><div><div dir="ltr"><div>Jacob Bandes-Storch<br></div></div></div></div>
<br><div class="gmail_quote">On Fri, Dec 18, 2015 at 1:46 PM, Joe Groff 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-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><span><br><div><blockquote type="cite"><div>On Dec 18, 2015, at 4:42 AM, Amir Michail via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div><div style="word-wrap:break-word">Examples:<div><br></div><div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo">&gt;&gt;&gt; l=[1,2,3,4,5]</div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo">&gt;&gt;&gt; l[-1]</div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo">5</div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo">&gt;&gt;&gt; l[-2]</div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo">4</div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo">&gt;&gt;&gt; l[2:4]</div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo">[3, 4]</div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo">&gt;&gt;&gt; l[2:]</div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo">[3, 4, 5]</div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo">&gt;&gt;&gt; l[-2:]</div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo">[4, 5]</div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo">&gt;&gt;&gt; l[:3]</div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo">[1, 2, 3]</div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo">&gt;&gt;&gt; l[::2]</div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo">[1, 3, 5]</div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo">&gt;&gt;&gt; l[::]</div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo">[1, 2, 3, 4, 5]</div></div>
</div></div></blockquote><br></div></span><div>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&#39;ll quietly load the wrong element instead of trapping. I&#39;d prefer something like D&#39;s `$-n` syntax for explicitly annotating end-relative indexes.</div><div><br></div><div>-Joe</div><br>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=P-2BsYbBZHRBuLDBJaL4DIKDNfkkjpROowTyRAObV11qwPtsqLyXmkhZo-2F0LDp0iAlwa-2FFb9Mv41d-2FKmn4-2FrdNuLAaIGoYLAE-2BgMekN6nrCE-2BoJaqVXi-2BH2wUBuZBKGQnxGu3D8npmq20fJ4uLR9YPzvf30xyGLhvSOCY-2BkuvH9tT9ghOPraahKgkrap0hrBDdlFPcNg1NfN5eb69LwrTp5H76J17QNWLCfXl33Z-2Bt8Z4-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0px!important;margin:0px!important;padding:0px!important">
</div>
<br>_______________________________________________<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/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div></div>