<div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">The second half on mutating is wrong. Please ignore that.</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif">Zhaoxin</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 17, 2016 at 8:47 PM, zh ao <span dir="ltr"><<a href="mailto:owenzx@gmail.com" target="_blank">owenzx@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">Xcode Version 7.3.1 (7D1014), swift 2.2 along with Xcode.</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif">Zhaoxin</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 17, 2016 at 8:46 PM, zh ao <span dir="ltr"><<a href="mailto:owenzx@gmail.com" target="_blank">owenzx@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">It seams that I encountered bugs in function advancedBy().</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default"><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,132,0)"><span>//: Playground - noun: a place where people can play</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal;min-height:13px"><span></span><br></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="color:rgb(187,44,162)">import</span><span> Foundation</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal;min-height:13px"><span></span><br></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="color:rgb(187,44,162)">do</span><span> {</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span> </span><span style="color:rgb(187,44,162)">var</span><span> str = </span><span style="color:rgb(209,47,27)">"abcdefg"</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span> </span><span style="color:rgb(187,44,162)">var</span><span> range = str.</span><span style="color:rgb(112,61,170)">startIndex</span><span>..<str.</span><span style="color:rgb(112,61,170)">endIndex</span><span> </span><span style="color:rgb(0,132,0)">// 0..<7</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span> str += </span><span style="color:rgb(209,47,27)">"hijklmn"</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span> range.</span><span style="color:rgb(112,61,170)">endIndex</span><span> = str.</span><span style="color:rgb(112,61,170)">endIndex</span><span> </span><span style="color:rgb(0,132,0)">// 0..<14</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span> </span><span style="color:rgb(187,44,162)">let</span><span> index = range.</span><span style="color:rgb(112,61,170)">startIndex</span><span>.</span><span style="color:rgb(61,29,129)">advancedBy</span><span>(</span><span style="color:rgb(39,42,216)">10</span><span>)</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)"> </span><span>//fatal error: cannot increment endIndex</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span>}</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal;min-height:13px"><span></span><br></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="color:rgb(187,44,162)">do</span><span> {</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span> </span><span style="color:rgb(187,44,162)">var</span><span> str = </span><span style="color:rgb(209,47,27)">"abcdefg"</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span> str += </span><span style="color:rgb(209,47,27)">"hijklmn"</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal;min-height:13px"><span> </span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span> </span><span style="color:rgb(187,44,162)">var</span><span> range = str.</span><span style="color:rgb(112,61,170)">startIndex</span><span>..<str.</span><span style="color:rgb(112,61,170)">endIndex</span><span> </span><span style="color:rgb(0,132,0)">// 0..<14</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span> </span><span style="color:rgb(187,44,162)">let</span><span> index = range.</span><span style="color:rgb(112,61,170)">startIndex</span><span>.</span><span style="color:rgb(61,29,129)">advancedBy</span><span>(</span><span style="color:rgb(39,42,216)">10</span><span>)</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span> range </span><span style="color:rgb(0,132,0)">// 0..<14</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span>}</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal;min-height:13px"><span></span><br></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span style="color:rgb(187,44,162)">do</span><span> {</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span> </span><span style="color:rgb(187,44,162)">var</span><span> range = </span><span style="color:rgb(39,42,216)">0</span><span>..<</span><span style="color:rgb(39,42,216)">7</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span> </span><span style="color:rgb(187,44,162)">let</span><span> index = range.</span><span style="color:rgb(112,61,170)">startIndex</span><span>.</span><span style="color:rgb(61,29,129)">advancedBy</span><span>(</span><span style="color:rgb(39,42,216)">10</span><span>)</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span> range </span><span style="color:rgb(0,132,0)">// 0..<7</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,132,0)">
</p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span>}</span></p><p style="font-family:Menlo;margin:0px;font-size:11px;line-height:normal"><span><br></span></p><p style="margin:0px;line-height:normal"><font face="georgia, serif">There are three do blocks. All codes are similar.</font></p><p style="margin:0px;line-height:normal"><font face="georgia, serif"><br></font></p><p style="margin:0px;line-height:normal"><font face="georgia, serif">First block and second block is the almost same. But I encounter an error in the first block, saying "fatal error: cannot increment endIndex</font><span style="font-family:georgia,serif">". It shouldn't appear as the endIndex of range is 14 instead 7.</span></p><p style="margin:0px;line-height:normal"><span style="font-family:georgia,serif"><br></span></p><p style="margin:0px;line-height:normal"><span style="font-family:georgia,serif">Second block and third block both used function advancedBy, however, in the second block, the method is from </span><font face="georgia, serif">BidirectionalIndexType, </font></p><p style="margin:0px;line-height:normal"><font face="georgia, serif"><br></font></p></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_default"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(112,61,170)"><span style="color:rgb(187,44,162)">extension</span><span style="color:rgb(0,0,0)"> </span><span>BidirectionalIndexType</span><span style="color:rgb(0,0,0)"> {</span></p></div><div class="gmail_default"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)"><span style="color:rgb(0,0,0)"> </span><span>@warn_unused_result</span></p></div><div class="gmail_default"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span> </span><span style="color:rgb(187,44,162)">public</span><span> </span><span style="color:rgb(187,44,162)">func</span><span> advancedBy(n: </span><span style="color:rgb(112,61,170)">Self</span><span>.</span><span style="color:rgb(112,61,170)">Distance</span><span>) -> </span><span style="color:rgb(112,61,170)">Self</span></p></div><div class="gmail_default"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)"><span style="color:rgb(0,0,0)"> </span><span>@warn_unused_result</span></p></div><div class="gmail_default"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span> </span><span style="color:rgb(187,44,162)">public</span><span> </span><span style="color:rgb(187,44,162)">func</span><span> advancedBy(n: </span><span style="color:rgb(112,61,170)">Self</span><span>.</span><span style="color:rgb(112,61,170)">Distance</span><span>, limit: </span><span style="color:rgb(112,61,170)">Self</span><span>) -> </span><span style="color:rgb(112,61,170)">Self</span></p></div><div class="gmail_default"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>}</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span><br></span></p></div></blockquote><div class="gmail_default" style="display:inline"><font face="georgia, serif">in the third block, it is RandomAccessIndexType,</font></div><br><div class="gmail_default"><p style="margin:0px;line-height:normal">
</p></div><div><div class="gmail_default" style="display:inline"><font face="georgia, serif"><br></font></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div class="gmail_default" style="display:inline"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(112,61,170)"><span style="color:rgb(187,44,162)">extension</span><span style="color:rgb(0,0,0)"> </span><span>Int</span><span style="color:rgb(0,0,0)"> : </span><span>RandomAccessIndexType</span><span style="color:rgb(0,0,0)"> {</span></p></div></div><div><div class="gmail_default" style="display:inline"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)"> </span><span>/// Returns the next consecutive value after `self`.</span></p></div></div><div><div class="gmail_default" style="display:inline"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span> </span><span style="color:rgb(0,132,0)">///</span></p></div></div><div><div class="gmail_default" style="display:inline"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)"> </span><span>/// - Requires: The next value is representable.</span></p></div></div><div><div class="gmail_default" style="display:inline"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span> </span><span style="color:rgb(187,44,162)">public</span><span> </span><span style="color:rgb(187,44,162)">func</span><span> successor() -> </span><span style="color:rgb(112,61,170)">Int</span></p></div></div><div><div class="gmail_default" style="display:inline"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)"> </span><span>/// Returns the previous consecutive value before `self`.</span></p></div></div><div><div class="gmail_default" style="display:inline"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span> </span><span style="color:rgb(0,132,0)">///</span></p></div></div><div><div class="gmail_default" style="display:inline"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)"> </span><span>/// - Requires: The previous value is representable.</span></p></div></div><div><div class="gmail_default" style="display:inline"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span> </span><span style="color:rgb(187,44,162)">public</span><span> </span><span style="color:rgb(187,44,162)">func</span><span> predecessor() -> </span><span style="color:rgb(112,61,170)">Int</span></p></div></div><div><div class="gmail_default" style="display:inline"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span> </span><span style="color:rgb(187,44,162)">public</span><span> </span><span style="color:rgb(187,44,162)">func</span><span> distanceTo(other: </span><span style="color:rgb(112,61,170)">Int</span><span>) -> </span><span style="color:rgb(112,61,170)">Distance</span></p></div></div><div><div class="gmail_default" style="display:inline"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span> </span><span style="color:rgb(187,44,162)">public</span><span> </span><span style="color:rgb(187,44,162)">func</span><span> advancedBy(n: </span><span style="color:rgb(112,61,170)">Distance</span><span>) -> </span><span style="color:rgb(112,61,170)">Int</span></p></div></div><div><div class="gmail_default" style="display:inline"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>}</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span><br></span></p></div></div></blockquote><font face="Menlo"><div class="gmail_default" style="font-family:georgia,serif;display:inline">So the range in the third block after advancedBy is unchanged. It makes sense here. But I think people may feel strange as one is a mutating function and the other is not.</div></font><div><font face="Menlo"><div class="gmail_default" style="font-family:georgia,serif;display:inline"><br></div></font></div><div><div class="gmail_default" style="font-family:georgia,serif">Zhaoxin</div><br></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>