<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=""><div class=""><div><blockquote type="cite" class=""><div class="">On Apr 9, 2016, at 5:58 PM, Haravikk via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 9 Apr 2016, at 10:50, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a>> wrote:</div><div class=""><br class="">But, ranges are useful for more than just stride, and so I would say it doesn't make sense to have an intrinsic direction for Range, which pointedly has lowerBound and upperBound but not start and end. For sample, there shouldn't be (0...9).contains(1) and (9...0).contains(1).<br class=""></div></blockquote><div class=""><br class=""></div><div class="">While I can appreciate that, I wonder if it’s really that important that 0…9 and 9…0 are identical? As long as we can be clear on which direction of range we want to generate (so probably still need two new operators), can tell what the direction is, and can convert between them if we need to for some reason (reverse should be fine for that?), then I think we’re okay.</div><div class=""><br class=""></div><div class="">i.e- 9 … 0 would still cause an error at compile or run-time, we’d have some other operator for doing that, not sure what, plus 9 ..> 0, with both explicitly creating ranges in the reverse direction to avoid mistakes with the order or for computed indices. When it comes down to it the current Range has an implicitly forward direction, so I don’t see the problem with having the same in reverse personally.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">I dunno, at the very least we might want to consider overloading the striding method as <font face="Monaco" class="">.striding(forwardBy:)</font> and <font face="Monaco" class="">.striding(backwardBy:)</font> or something similar, each taking a positive value of some kind to help avoid mistakes in cases where the stride size is computed rather than constant, this would make it more explicit at least.</div></div></div></div></blockquote></div><br class=""></div></div><div class="">I can’t imagine any scenario in which getting the step's sign wrong wouldn’t just be a typo. Why not just assign it the correct sign during the init function?<div class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">0</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class=""> ... </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">6</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">).</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(49, 89, 93);" class="">striding</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">(by: </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">2</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">) </span><span style="font-variant-ligatures: no-common-ligatures;" class="">// [0, 2, 4, 6], end > start, so stride = by</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">6</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> ... </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">0</span><span style="font-variant-ligatures: no-common-ligatures;" class="">).</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(49, 89, 93);" class="">striding</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(by: </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">2</span><span style="font-variant-ligatures: no-common-ligatures;" class="">) </span><span style="color: rgb(0, 132, 0); font-variant-ligatures: no-common-ligatures;" class="">// [6, 4, 2, 0], </span><span style="color: rgb(0, 132, 0);" class="">start > end, so stride = -by</span></div><div class=""><span style="color: rgb(0, 132, 0);" class=""><br class=""></span></div><div class="">(OTOH, I don’t understand why 6…0 is currently a crash, rather than the, IMHO, obviously intended sequence of “6,5,4,3,2,1,0”, so maybe I’m not the best person to ask)</div><div class=""><br class=""></div><div class="">- Dave Sweeris</div></div></div></div></div></div></body></html>