<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="">Agreed. My original response, which did not get reply all’ed:<div class=""><br class=""></div><div class="">To me, this notation seems slightly confusing. The current syntax with an inner loop makes the time complexity apparent, and more accurately represents what you are trying to do (in this example, build the Cartesian product of suits and ranks).<br class=""><br class="">The "for x in suits, y in ranks" notation hides the inner loop(s) and is not immediately apparent in its function (does this construct increment both x and y every iteration?). I definitely have seen the type of construct you are proposing many times, so there is value in considering a more concise way of writing it, but perhaps there is better notation. <br class=""><br class="">FKL</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 9, 2015, at 4:31 PM, J. Cheyo Jimenez 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 class=""><div class="">The proposed extension looks to me like is iterating both the suits and rank at the same time. In that case I think is a great idea.</div><div class=""><br class=""></div><div class=""><span style="font-size:12.8px" class="">var cards: [(Suit,Rank)] = []</span><br style="font-size:12.8px" class=""><span style="font-size:12.8px" class="">for x in suits, y in ranks {</span><br style="font-size:12.8px" class=""><span style="font-size:12.8px" class=""> cards.append((x,y))</span><br style="font-size:12.8px" class=""><span style="font-size:12.8px" class="">}</span></div></div><div class=""><span style="font-size:12.8px" class=""><br class=""></span></div><div class=""><span style="font-size:12.8px" class="">What I am expecting:</span><br class=""></div><div class=""><span style="font-size:12.8px" class=""><br class=""></span></div><div class=""><span style="font-size:12.8px" class="">x1, y1</span></div><div class=""><span style="font-size:12.8px" class="">x2, y2</span></div><div class=""><span style="font-size:12.8px" class="">x3, y3</span></div><div class=""><span style="font-size:12.8px" class="">etc</span></div><div class=""><span style="font-size:12.8px" class=""><br class=""></span></div><div class=""><span style="font-size:12.8px" class="">This reminds me that this is one of the ways I use the C-style for-loop. </span></div><div class=""><span style="font-size:12.8px" class="">The alternative now:</span></div><div class=""><span style="font-size:12.8px" class=""><br class=""></span></div><div class=""><span class="">for</span><span class=""> (index, x) </span><span class="">in</span><span class=""> </span><span class="">suits</span><span class="">.</span><span class="">enumerate</span><span class="">(){</span></div><div class=""><span class=""> </span><span class="">let</span><span class=""> y = </span><span class="">ranks</span><span class="">[index]</span></div><div class=""><span class=""> </span><span class="">cards</span><span class="">.</span><span class="">append</span><span class="">((x,y))</span></div><div class=""><p class=""><span class="">}</span></p><p class=""><br class=""></p></div><div class=""><span style="font-size:12.8px" class=""><br class=""></span></div><div class=""><span style="font-size:12.8px" class=""><br class=""></span></div><div class=""><br class=""></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Wed, Dec 9, 2015 at 12:00 PM, Chris Eidhof via swift-evolution <span dir="ltr" class=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I think it could be really nice to extend the for-loop so that it can have multiple clauses. Much like in the if-let with multiple clauses, I could imagine a for-loop with multiple clauses:<br class="">
<br class="">
var cards: [(Suit,Rank)] = []<br class="">
for x in suits, y in ranks {<br class="">
cards.append((x,y))<br class="">
}<br class="">
<br class="">
This would be the same as writing:<br class="">
<br class="">
var cards: [(Suit,Rank)] = []<br class="">
for x in suits {<br class="">
for y in ranks {<br class="">
cards.append((x,y))}<br class="">
}<br class="">
}<br class="">
<br class="">
You could also do something like:<br class="">
<br class="">
for x in input1, y in (x..<end) {<br class="">
// Do something with (x,y)<br class="">
}<br class="">
<br class="">
In fact, once we would have that, we could combine both if-let and for, and make it more general, to end up with something like Haskell’s do-notation or C#’s LINQ. But that might be taking it too far...<br class="">
<br class="">
Chris<br class="">
_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
</blockquote></div><br class=""></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=xuNk3-2BDhTcLCDO7Sfs7vOCSNM9OdwMfwhE-2B5u-2B7ewF43uJuyRm-2FJv47-2BUiRI2jansD3ChNeeLMBW-2Bbo2TSQpV4Y3kxUeLLUnwS1yzbqu0A3tAYq888X0qJvsJc1qttwbBBdk42tWcvH6l0LQgmhDRMCNothP1VezD4W5fOvOJCwVWvLbv3eYeSlAU-2Ft7S-2F-2BzYAPm-2Bj02gvyoEi4p0HWIjA-3D-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></body></html>