<html><head></head><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue-Light, Helvetica Neue Light, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px"><div tabindex="0" style="outline: none 0px; display: table; width: 823px; box-sizing: border-box; padding-top: 12px; padding-left: 0px; font-family: 'Helvetica Neue', 'Segoe UI', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px;" id="yui_3_16_0_1_1474452612499_41650"><div style="display: table-cell; width: auto; word-wrap: break-word; word-break: break-word;" id="yui_3_16_0_1_1474452612499_41651"><div id="yui_3_16_0_1_1474452612499_41652"><div id="yui_3_16_0_1_1474452612499_41653"><div style="font-family: HelveticaNeue-Light, 'Helvetica Neue Light', 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 16px;" id="yui_3_16_0_1_1474452612499_41654"><div id="yui_3_16_0_1_1474452612499_41655"><span id="yui_3_16_0_1_1474452612499_41656">Just to make myself (more) clear, I don't ask for any solutions because I've known them already. I even have made my own custom operators for all the purposes so I have balance operators. Of course they're sugar candy syntax, but isn't that one of the reasons why Swift is great? If you look at previously accepted proposals, some of them are sugar syntax as well. So, I don't think I'm the first one here.</span></div><div id="yui_3_16_0_1_1474452612499_41657"><br clear="none" id="yui_3_16_0_1_1474452612499_41658"></div><div dir="ltr" id="yui_3_16_0_1_1474452612499_41659"><span id="yui_3_16_0_1_1474452612499_41660">I'm proposing solutions that is built right into the language syntax so everybody else who need such operations doesn't have to make their own custom operators (like me) again and again and again. After all, if there is ..&lt; operator, why can't we have ..&gt; operator too, right? Why should we use the ugly `reversed()` and `stride()` function? If we have to use such `stride()` function that is able to create any possible variations of range, why do we have ... operator in the first place? Isn't it just sugar syntax?</span></div><div id="yui_3_16_0_1_1474452612499_41661"></div><div id="yui_3_16_0_1_1474452612499_41662"><br clear="none" id="yui_3_16_0_1_1474452612499_41663"></div><div id="yui_3_16_0_1_1474452612499_41664">But after I thought about it again, I think half-opened range doesn't really make any senses. The ..&lt; operator (and my proposed ..&gt; operator) should be removed. Or we have to accept the consequences that we also need the other accompanying operators. The … operator with optional `step` attribute that is able to go both ways is more important that half-opened range operator.&nbsp;</div><div id="yui_3_16_0_1_1474452612499_41665"><br clear="none" id="yui_3_16_0_1_1474452612499_41666"></div><div id="yui_3_16_0_1_1474452612499_41667">This is all because the lack of c-style for-loop syntax in Swift. Well, I'm not against it, I like it in fact. It makes Swift syntax more elegant. However, I think the range syntax needs to be more flexible and complete as well, so we don't miss the old c-style for-loop syntax.</div><div id="yui_3_16_0_1_1474452612499_41668"><br clear="none" id="yui_3_16_0_1_1474452612499_41669"></div><div dir="ltr" id="yui_3_16_0_1_1474452612499_41670">Regards,</div></div></div></div></div></div><div></div><div>&nbsp;</div><div class="signature" id="yui_3_16_0_1_1474452612499_41620"><div><br></div>–Mr Bee<div id="yui_3_16_0_1_1474452612499_41619"><br></div></div> <div class="qtdSeparateBR"><br><br></div><div class="yahoo_quoted" style="display: block;"> <div style="font-family: HelveticaNeue-Light, Helvetica Neue Light, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"> <div dir="ltr"><font size="2" face="Arial"> Pada Rabu, 21 September 2016 16:11, Charlie Monroe &lt;charlie@charliemonroe.net&gt; menulis:<br></font></div>  <br><br> <div class="y_msg_container"><div id="yiv5999245092"><div>Hi,<div class="yiv5999245092"><br clear="none" class="yiv5999245092"></div><div class="yiv5999245092">AFAIK, these all would be very much sugar for:</div><div class="yiv5999245092"><br clear="none" class="yiv5999245092"></div><div class="yiv5999245092">1) (1 ..&lt; 5).reversed()</div><div class="yiv5999245092">2) The same as above: (1 ... 5).reversed() does exactly what you want.</div><div class="yiv5999245092">3) Kind of makes sense to me to include &gt;.., &nbsp;though to be thorough, you'd need to add &gt;.&lt; as well - that's a weird looking operator...</div><div class="yiv5999245092">4) There's a global function for this:&nbsp;<span class="yiv5999245092" style="font-family:Menlo;font-size:9px;color:rgb(62, 30, 129);">stride</span><span class="yiv5999245092" style="font-family:Menlo;font-size:9px;">(from: </span><span class="yiv5999245092" style="font-family:Menlo;font-size:9px;color:rgb(39, 42, 216);">1</span><span class="yiv5999245092" style="font-family:Menlo;font-size:9px;">, to: </span><span class="yiv5999245092" style="font-family:Menlo;font-size:9px;color:rgb(39, 42, 216);">10</span><span class="yiv5999245092" style="font-family:Menlo;font-size:9px;">, by: </span><span class="yiv5999245092" style="font-family:Menlo;font-size:9px;color:rgb(39, 42, 216);">2</span><span class="yiv5999245092" style="font-family:Menlo;font-size:9px;">)</span></div><div class="yiv5999245092"><br clear="none" class="yiv5999245092"></div><div class="yiv5999245092">Charlie</div><div class="yiv5999245092"><br clear="none" class="yiv5999245092"></div><div class="yiv5999245092"><br clear="none" class="yiv5999245092"><div><blockquote class="yiv5999245092" type="cite"><div class="yiv5999245092yqt2826114478" id="yiv5999245092yqt29187"><div class="yiv5999245092">On Sep 21, 2016, at 9:49 AM, Mr Bee via swift-evolution &lt;<a rel="nofollow" shape="rect" class="yiv5999245092" ymailto="mailto:swift-evolution@swift.org" target="_blank" href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:</div><br clear="none" class="yiv5999245092Apple-interchange-newline"><div class="yiv5999245092"><div class="yiv5999245092"><div class="yiv5999245092" style="background-color:rgb(255, 255, 255);font-family:HelveticaNeue-Light, 'Helvetica Neue Light', 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:16px;"><div class="yiv5999245092" id="yiv5999245092yui_3_16_0_1_1474441093361_6256"><span class="yiv5999245092" id="yiv5999245092yui_3_16_0_1_1474441093361_8022">Hi,</span></div><div class="yiv5999245092" id="yiv5999245092yui_3_16_0_1_1474441093361_6257"><span class="yiv5999245092"><br clear="none" class="yiv5999245092"></span></div><div class="yiv5999245092" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092" id="yiv5999245092yui_3_16_0_1_1474441093361_6258">I'm a Swift newbie so forgive me if my question sounds a bit silly, or perhaps had been asked previously. My question is, why Swift doesn't have built-in operator for backward or decremented range? Especially to be used in for-in loop.</span></div><div class="yiv5999245092" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092"><br clear="none" class="yiv5999245092"></span></div><div class="yiv5999245092" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092" id="yiv5999245092yui_3_16_0_1_1474441093361_6334">Swift only has&nbsp;... (closed range) and ..&lt; (half-opened range) that both go forward (incremented). To use backward (decremented) range, we have to use several techniques (stride, sequence, etc). Of course those techniques work well. But I don't think they're very swifty, so to say.</span></div><div class="yiv5999245092" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092"><br clear="none" class="yiv5999245092"></span></div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092" id="yiv5999245092yui_3_16_0_1_1474441093361_6496">So, is it possible to propose a new operator and a modification to existing operator regarding range? Would such proposal be considered and implemented after Swift 3? If it is, here's my pre-proposal about it.</span></div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092"><br clear="none" class="yiv5999245092"></span></div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092" id="yiv5999245092yui_3_16_0_1_1474441093361_6497">1. Add new ..&gt; operator that goes backward (decremented) as companion to ..&lt; operator that goes forward (incremented).</span></div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092"><br clear="none" class="yiv5999245092"></span></div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092">Example:</span></div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092">&nbsp; for i in 1 ..&lt; 5 { print(i) }</span></div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092">will prints: 1 2 3 4</span></div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092">&nbsp; for i in 5 ..&gt; 1</span>&nbsp;{ print(i) }</div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092">will prints: 5 4 3 2</span></div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092"><br clear="none" class="yiv5999245092"></span></div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092" id="yiv5999245092yui_3_16_0_1_1474441093361_6699">2. Modify the ... operator to be able to go both ways. If the left operand is greater than the right, it goes backward (decremented). While if the left operand is less than the right, it goes forward (incremented).</span></div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092"><br clear="none" class="yiv5999245092"></span></div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092" id="yiv5999245092yui_3_16_0_1_1474441093361_6640">Example:</span></div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092" id="yiv5999245092yui_3_16_0_1_1474441093361_6645">&nbsp; for i in 1&nbsp;... 5</span>&nbsp;{ print(i) }</div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092" id="yiv5999245092yui_3_16_0_1_1474441093361_6646">will prints: 1 2 3 4 5</span></div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092" id="yiv5999245092yui_3_16_0_1_1474441093361_6647">&nbsp; for i in 5&nbsp;... 1</span>&nbsp;{ print(i) }</div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092">will prints: 5 4 3 2 1</span></div><div class="yiv5999245092" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092"><br clear="none" class="yiv5999245092"></span></div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092" id="yiv5999245092yui_3_16_0_1_1474441093361_7036">3. Add new pair of operator to accompany the ..&gt; and ..&lt; (half opened range on the right side) pair operator. It's &gt;.. and &lt;.. operators which are half opened range on the left side. As you might guess, the &gt;.. is the opposite of ..&gt; operator and the &lt;.. is the opposite of the ..&lt; operator.</span></div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092"><br clear="none" class="yiv5999245092"></span></div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092">Example:</span></div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092">&nbsp; for i in 1 &lt;.. 5 { print(i) }</span></div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092">will prints: 2 3 4 5</span></div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092">&nbsp; for i in 5 &gt;.. 1 { print(i) }</span></div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259">will prints: 4 3 2 1</div><div class="yiv5999245092" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092"><br clear="none" class="yiv5999245092"></span></div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092" id="yiv5999245092yui_3_16_0_1_1474441093361_7433">4. I would like to go even further by introducing a new attribute into for-in loop syntax. It's `step` keyword which is used to define the interval of the loop (like BASIC). Of course this additional attribute only works if the range is countable or indexable. If not, the compiler should complain.</span></div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092"><br clear="none" class="yiv5999245092"></span></div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092">Example:</span></div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092">&nbsp; for i in 1 ... 10 step 2</span>&nbsp;{ print(i) }</div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092">will prints: 1 3 5 7 9</span></div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_7513">&nbsp; for i in 10 ... 0 step 2 { print(i) }</div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_7514">will prints: 10 8 6 4 2 0</div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_7515"><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_7692" style="margin-top:0.1em;margin-bottom:0.1em;">&nbsp; for i in 1 ..&lt; 9 step 3 { print(i) }</div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_7693" style="margin-top:0.1em;margin-bottom:0.1em;">will prints: 1 3 6&nbsp;</div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_7693" style="margin-top:0.1em;margin-bottom:0.1em;">&nbsp; // note: 9 is omitted since it's on the opened side.</div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_7694"><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_7724" style="margin-top:0.1em;margin-bottom:0.1em;">&nbsp; for i in 9 &gt;.. 1 step 2 { print(i) }</div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_7725" style="margin-top:0.1em;margin-bottom:0.1em;">will prints: 7 5 3 1</div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_7726"><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_7766" style="margin-top:0.1em;margin-bottom:0.1em;"><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_7780" style="font-family:HelveticaNeue-Light, 'Helvetica Neue Light', 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;"></div></div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_7781" style="margin:0.1em 0px;padding:0px;display:block;font-family:HelveticaNeue-Light, 'Helvetica Neue Light', 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;">&nbsp; // note: 9 is omitted since it's on the opened side.</div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_7781" style="margin:0.1em 0px;padding:0px;display:block;font-family:HelveticaNeue-Light, 'Helvetica Neue Light', 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:16px;font-style:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;"><br clear="none" class="yiv5999245092"></div></div></div></div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092" id="yiv5999245092yui_3_16_0_1_1474441093361_6737">I hope you get the idea. I think such a rich for-in loop syntax would make Swift smarter, more robust, and easier to be learned and understood. They're also required since the flexibiliy of c-style for-loop is no longer available from Swift 3 and on. Decremented or backward range is sometimes needed in some algorithms. Making it built into the language would be better, instead of using non-language solutions. This proposal also doesn't break old codes since it doesn't change the old behavior.</span></div><div class="yiv5999245092" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092"><br clear="none" class="yiv5999245092"></span></div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092" id="yiv5999245092yui_3_16_0_1_1474441093361_6895">If such proposal is possible to be implemented —or at least considered— in the next version of Swift, I'll do the work of the formal proposal on GitHub. If it's not, well, I don't want to spend my time doing something that will be ignored.</span></div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092"><br clear="none" class="yiv5999245092"></span></div><div class="yiv5999245092" dir="ltr" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092">Thank you.</span></div><div class="yiv5999245092" id="yiv5999245092yui_3_16_0_1_1474441093361_6259"><span class="yiv5999245092"><br clear="none" class="yiv5999245092"></span></div><div class="yiv5999245092"></div><div class="yiv5999245092" id="yiv5999245092yui_3_16_0_1_1474441093361_6092">Regards,&nbsp;</div><div class="yiv5999245092signature" id="yiv5999245092yui_3_16_0_1_1474441093361_7170"><div class="yiv5999245092" id="yiv5999245092yui_3_16_0_1_1474441093361_7169"><br clear="none" class="yiv5999245092"></div>–Mr Bee<div class="yiv5999245092" id="yiv5999245092yui_3_16_0_1_1474441093361_7171"><br clear="none" class="yiv5999245092"></div><div class="yiv5999245092" id="yiv5999245092yui_3_16_0_1_1474441093361_7171">PS. I apologize if my English isn't well enough. I hope you all understand what I meant. :)</div><div class="yiv5999245092" id="yiv5999245092yui_3_16_0_1_1474441093361_7171"><br clear="none" class="yiv5999245092"></div></div></div></div>_______________________________________________<br clear="none" class="yiv5999245092">swift-evolution mailing list<br clear="none" class="yiv5999245092"><a rel="nofollow" shape="rect" class="yiv5999245092" ymailto="mailto:swift-evolution@swift.org" target="_blank" href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br clear="none" class="yiv5999245092">https://lists.swift.org/mailman/listinfo/swift-evolution<br clear="none" class="yiv5999245092"></div></div></blockquote></div><br clear="none" class="yiv5999245092"></div></div></div><br><br></div>  </div> </div>  </div></div></body></html>