<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=""><div class="">I like the idea of the of the bounded subscript, however the optional one I feel could be used for clumsy code.</div><div class=""><br class=""></div><div class="">.first and .last have value, but once you start stepping several arbitrary indices in, then that code is likely fragile?</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">I can think of ‘within’, ‘inside’ and ‘intersecting’ as alternative names for ‘bounded’ that attempt to explain what is going on:</div><div class=""><br class=""></div><div class="">let&nbsp;a&nbsp;=&nbsp;[1,&nbsp;2,&nbsp;3]</div><div class=""><br class=""></div><div class="">a[within:&nbsp;0&nbsp;..&lt;&nbsp;5]&nbsp;// [1, 2, 3]</div><div class="">a[inside:&nbsp;0&nbsp;..&lt;&nbsp;5]&nbsp;// [1, 2, 3]</div><div class="">a[intersecting:&nbsp;0&nbsp;..&lt;&nbsp;5]&nbsp;// [1, 2, 3]</div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On 28 Apr 2016, at 10:11 PM, Luis Henrique B. Sousa 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 dir="ltr" class=""><div class="gmail_extra"><div class=""><div class="gmail_signature"><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div style="font-size:small" class="">As we have discussed throughout this thread, the initial proposal was modified to include alternative subscript methods instead of modifying the default operator/subscript behaviour.&nbsp;</div><div style="font-size:small" class="">The first draft is here:&nbsp;<a href="https://github.com/luish/swift-evolution/blob/more-lenient-subscripts/proposals/nnnn-more-lenient-collections-subscripts.md" class="">https://github.com/luish/swift-evolution/blob/more-lenient-subscripts/proposals/nnnn-more-lenient-collections-subscripts.md</a></div><div style="font-size:small" class=""><br class=""></div><div style="font-size:small" class="">I've also put this as a gist so that you can leave comments with respect to the proposal document itself. Any suggestion or help is very welcome.</div><div style="font-size:small" class=""><a href="https://gist.github.com/luish/832c34ee913159f130d97a914810dbd8" class="">https://gist.github.com/luish/832c34ee913159f130d97a914810dbd8</a></div><div style="font-size:small" class=""><br class=""></div><div style="font-size:small" class="">Regards,</div><div class=""><br class="">- Luis</div></div></div></div></div></div></div></div></div></div>
<br class=""><div class="gmail_quote">On Mon, Apr 11, 2016 at 1:23 PM, Luis Henrique B. Sousa <span dir="ltr" class="">&lt;<a href="mailto:lshsousa@gmail.com" target="_blank" class="">lshsousa@gmail.com</a>&gt;</span> wrote:<br class=""><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 dir="ltr" class="">This proposal seeks to provide a safer <font face="monospace, monospace" class="">..&lt;</font> (aka half-open range operator) in order to avoid **Array index out of range** errors in execution time.<br class=""><br class="">Here is my first draft for this proposal: <a href="https://github.com/luish/swift-evolution/blob/half-open-range-operator/proposals/nnnn-safer-half-open-range-operator.md" target="_blank" class="">https://github.com/luish/swift-evolution/blob/half-open-range-operator/proposals/nnnn-safer-half-open-range-operator.md</a><br class=""><br class="">In short, doing that in Swift causes a runtime error:<div class=""><p class=""><font face="monospace, monospace" class=""><span class="">let</span><span class=""> a </span><span class="">=</span><span class=""> [</span><span class="">1</span><span class="">,</span><span class="">2</span><span class="">,</span><span class="">3</span><span class="">]<br class=""></span><span class="">let</span><span class=""> b </span><span class="">=</span><span class=""> a[</span><span class="">0</span><span class="">..&lt;</span><span class="">5</span><span class="">]<br class=""></span><span class="">print</span><span class="">(b)</span></font></p><p class=""><span class="">&gt; Error running code:&nbsp;<br class=""></span>&gt; fatal error: Array index out of range</p><p class=""><span class="">The proposed solution is to slice the array retur</span>ning all elements that are below the half-open operator, even though the number of elements is lesser than the ending of the half-open operator. So the example above would return [1,2,3]. <br class="">We can see this very behaviour in other languages, such as Python and Ruby as shown in the proposal draft.</p><p class="">This would eliminate the need for verifications on the array size before slicing it -- and consequently runtime errors in cases when the programmer didn't. <br class=""><br class="">Viewing that it is my very first proposal, any feedback will be helpful.</p></div><div class=""><div class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class="">Thanks!</div><div class=""></div><br class=""></div><div class="">Luis Henrique Borges</div><div class="">@luishborges</div></div></div></div></div></div></div></div></div>
</div>
</blockquote></div><br class=""></div></div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>