<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">... and ..< aren't privileged by the language in any way; they're equivalent to calling Range(start: x, end: y). It would be nice to add more convenience initializers to Range, but I don't want to see the operators go, and I don't think a free function is the best interface.<div class=""><br class=""></div><div class="">Austin<br class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 8, 2015, at 11:01 AM, Kyle Bashour 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=""><div dir="ltr" class=""><div style="font-size:13px" class="">Based on much of the discussion regarding removing C-style for-loops, I'd like to propose a discussion on revamping how range works in Swift. The lack of a reverse range operator and the fact and the range operator and stride() seem to do a lot of the same work have made me wonder why there isn't merely a range() function, as in Python. </div><div style="font-size:13px" class=""><br class=""></div><div style="font-size:13px" class="">I believe this would be easier for newcomers to learn, remove the need for stride() (though there are probably use cases for stride() I don't know about, I haven't used it too much), and actually be more clear than ..< and ...</div><div style="font-size:13px" class=""><br class=""></div><div style="font-size:13px" class=""><br class=""></div><div style="font-size:13px" class="">Here are some examples of how it could work:<br class=""></div><div style="font-size:13px" class=""><br class=""></div><div style="font-size:13px" class="">range(10) // equivalent to 0..<10</div><div style="font-size:13px" class="">range(-1, to: 10) // equivalent to -1..<10</div><div style="font-size:13px" class="">range(10, through: 0) equivalent to (0...10).reverse()</div><div style="font-size:13px" class="">range(0, through: 10, by: 2) // equivalent to <span style="background-color:rgba(255,255,255,0)" class=""><span style="font-style:inherit;font-variant:inherit;margin:0px;padding:0px;border:0px;line-height:inherit;vertical-align:baseline" class="">0.stride</span><span style="font-style:inherit;font-variant:inherit;margin:0px;padding:0px;border:0px;line-height:inherit;vertical-align:baseline" class="">(through</span><span style="font-style:inherit;font-variant:inherit;margin:0px;padding:0px;border:0px;line-height:inherit;vertical-align:baseline" class="">:</span><span style="font-style:inherit;font-variant:inherit;margin:0px;padding:0px;border:0px;line-height:inherit;vertical-align:baseline" class=""> </span><span style="font-style:inherit;font-variant:inherit;margin:0px;padding:0px;border:0px;line-height:inherit;vertical-align:baseline" class="">10</span><span style="font-style:inherit;font-variant:inherit;margin:0px;padding:0px;border:0px;line-height:inherit;vertical-align:baseline" class="">,</span><span style="font-style:inherit;font-variant:inherit;margin:0px;padding:0px;border:0px;line-height:inherit;vertical-align:baseline" class=""> </span><span style="font-style:inherit;font-variant:inherit;margin:0px;padding:0px;border:0px;line-height:inherit;vertical-align:baseline" class="">by</span><span style="font-style:inherit;font-variant:inherit;margin:0px;padding:0px;border:0px;line-height:inherit;vertical-align:baseline" class="">:</span><span style="font-style:inherit;font-variant:inherit;margin:0px;padding:0px;border:0px;line-height:inherit;vertical-align:baseline" class=""> </span><span style="font-style:inherit;font-variant:inherit;margin:0px;padding:0px;border:0px;line-height:inherit;vertical-align:baseline" class="">2</span><span style="font-style:inherit;font-variant:inherit;margin:0px;padding:0px;border:0px;line-height:inherit;vertical-align:baseline" class="">)</span></span></div><div style="font-size:13px" class=""><br class=""></div><div style="font-size:13px" class="">Or, to avoid a global function, .range() should probably be a function like stride, but with more features (equivalent to above)</div><div style="font-size:13px" class=""><br class=""></div><div style="font-size:13px" class="">10.range()</div><div style="font-size:13px" class="">-1.range(to: 10)</div><div style="font-size:13px" class="">10.range(through: 0)</div><div style="font-size:13px" class="">0.range(through: 10, by: 2)</div><div style="font-size:13px" class=""><br class=""></div><div style="font-size:13px" class="">Would love thoughts on why this is good or bad, and if it's worth creating an actual proposal. </div><div style="font-size:13px" class=""><br class=""></div><div style="font-size:13px" class="">Regards,</div><div style="font-size:13px" class=""><br class=""></div><div style="font-size:13px" class="">Kyle</div><div class=""><br class=""></div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=7XtDdMHRjqIUi4tzSjSp2pWQIyxYdP6woIWn4vwV5gcrhURVGfYofXWgd1K68JcprbYAU-2B-2F0x6u9nu5vLqrqJfDf9epaN5FVo-2FEaUiL-2F-2F0RIT7UiUS77wD25g8P69fbhzm1whfoAFUqFHKjf8pkuCmJ-2FK-2F8OhIq2lwuxy8Czd1yoqRkiNB6wdoXQn249aILAHvrhz5-2BYHMo8HwTgd1JS7qsJn7RhaoPh9oHHhtY2hDg-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
_______________________________________________<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=""></div></div></body></html>