<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On May 10, 2016, at 11:12 PM, Nicholas Maccharoli &lt;<a href="mailto:nmaccharoli@gmail.com" class="">nmaccharoli@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="gmail_default" style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)"><div style="color:rgb(34,34,34);font-family:arial,sans-serif" class=""><div class="gmail_default" style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)">Hello ​Swift Evolution community,​</div><div class="gmail_default" style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)"><br class=""></div><div class="gmail_default" style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)">Thank you so much for all the important feedback, this thread became more lively than I initially hoped for!</div><div class="gmail_default" style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)"><br class=""></div><div class="gmail_default" style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)">First let me address Xiaodi Wu's questions from earlier:&nbsp;</div><div class="gmail_default" style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)"><br class=""></div></div><blockquote class="gmail_quote" style="color:rgb(34,34,34);font-family:arial,sans-serif;margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><span style="font-size:12.8px" class="">What is your motivation for this change?</span></blockquote><div class="gmail_default"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px" class=""><br class=""></span></div><div class="gmail_default">After thinking about it maybe I overreacted with wanting to phase out `while true`.</div><div class="gmail_default">I know `while true` is a programming idiom found in most languages but I personally think expressions testing a single `Bool` literal</div><div class="gmail_default">like `while true { ... }` are just as tasteless as directly using `true` as in `if true { ... }` and might possibly signify that swift needs a better construct to express an infinite loop.</div><div class="gmail_default"><br class=""></div><div class="gmail_default">So after reading this thread's feedback I'm changing my tone and think we should leave `while true` alone and let it continue to be</div><div class="gmail_default">a valid way of expressing an infinite loop but maybe at the same time we should think of adding a more Swifty alternative.</div><div class="gmail_default"><br class=""></div><div class="gmail_default">As a source of inspiration I really like rust's solution of `loop { ... }`:&nbsp;<a href="https://doc.rust-lang.org/book/loops.html" class="">https://doc.rust-lang.org/book/loops.html</a></div><div class="gmail_default">but Swift already has a `repeat` statement so I initially thought of modifying the behaviour of `repeat` to allow omitting the trailing `while true` as to not bloat Swift with a new keyword.</div></div></div></div></blockquote><div><br class=""></div><div>Very interesting that there is precedence in Rust.&nbsp;</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_default" style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)"><div class="gmail_default"><br class=""></div><blockquote class="gmail_quote" style="color:rgb(34,34,34);font-family:arial,sans-serif;margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><span style="font-size:12.8px" class="">What problems are solved by forbidding `while true`?</span></blockquote><div style="color:rgb(34,34,34);font-family:arial,sans-serif" class=""><br class=""></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif" class=""><div class="gmail_default" style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19);display:inline">​As I said above, after thinking about it again I think we should keep `while true` but I want to talk about a possible issue with the</div></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif" class=""><div class="gmail_default" style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19);display:inline">`while true` idiom:</div></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif" class=""><span class="" style="color:rgb(39,78,19);font-family:'comic sans ms',sans-serif"><br class=""></span></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif" class=""><span class="" style="color:rgb(39,78,19);font-family:'comic sans ms',sans-serif"><div class="gmail_default" style="display:inline">​ &nbsp; &nbsp;​</div>let</span><span class="" style="color:rgb(39,78,19);font-family:'comic sans ms',sans-serif">&nbsp;foo:&nbsp;</span><span class="" style="color:rgb(39,78,19);font-family:'comic sans ms',sans-serif">Int<div class="gmail_default" style="display:inline">​&nbsp;</div></span></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif" class=""><span class="" style="color:rgb(39,78,19);font-family:'comic sans ms',sans-serif"><div class="gmail_default" style="display:inline">&nbsp; &nbsp; ​</div></span><span class="" style="color:rgb(39,78,19);font-family:'comic sans ms',sans-serif">while</span><span class="" style="color:rgb(39,78,19);font-family:'comic sans ms',sans-serif">&nbsp;</span><span class="" style="color:rgb(39,78,19);font-family:'comic sans ms',sans-serif">true</span><span class="" style="color:rgb(39,78,19);font-family:'comic sans ms',sans-serif">&nbsp;{&nbsp;</span><span class="" style="color:rgb(39,78,19);font-family:'comic sans ms',sans-serif">foo</span><span class="" style="color:rgb(39,78,19);font-family:'comic sans ms',sans-serif">&nbsp;=&nbsp;</span><span class="" style="color:rgb(39,78,19);font-family:'comic sans ms',sans-serif">5</span><span class="" style="color:rgb(39,78,19);font-family:'comic sans ms',sans-serif">;&nbsp;</span><span class="" style="color:rgb(39,78,19);font-family:'comic sans ms',sans-serif">break</span><span class="" style="color:rgb(39,78,19);font-family:'comic sans ms',sans-serif">&nbsp;}</span></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif" class=""><span class="" style="color:rgb(39,78,19);font-family:'comic sans ms',sans-serif"><div class="gmail_default" style="display:inline">​ &nbsp; &nbsp;​</div>print</span><span class="" style="color:rgb(39,78,19);font-family:'comic sans ms',sans-serif">(</span><span class="" style="color:rgb(39,78,19);font-family:'comic sans ms',sans-serif">foo</span><span class="" style="color:rgb(39,78,19);font-family:'comic sans ms',sans-serif">)</span></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif" class=""><span class="" style="color:rgb(39,78,19);font-family:'comic sans ms',sans-serif"><br class=""></span></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif" class=""><div class="gmail_default" style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)">​The above code will error out with the message "Constant 'foo' used before being initialized"​</div><div class="gmail_default" style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)">`while true` will always enter the body of the loop at least once but since `while` is a conditional statement this error occurs</div></div><div class="gmail_default">whereas this code works just fine:</div><div class="gmail_default"><br class=""></div><div class="gmail_default"><div class="gmail_default">&nbsp; &nbsp; let foo: Int</div><div class="gmail_default">&nbsp; &nbsp; repeat { foo = 5; break } while true</div><div class="gmail_default">&nbsp; &nbsp; print(foo)</div><div class="gmail_default"><br class=""></div><div class="gmail_default">since `repeat` will unconditionally enter the repeat block at least once.&nbsp;</div><div class="gmail_default">So I think my initial idea can be broken up into two distinct parts.</div><div class="gmail_default"><br class=""></div><div class="gmail_default">Part I: add a `while true` alternative</div><div class="gmail_default"><div class="gmail_default">----------------------------------------------------------------------------------------</div></div><div class="gmail_default"><br class=""></div><div class="gmail_default">So for the `while true` idiom replacement I want to propose adding something like a `loop { }` construct or possibly modifying the `repeat` keyword to take a statement modifier such as `sustained repeat { ... }`</div></div></div></div></div></blockquote><div><br class=""></div><div>I’m of the opinion that if it requires an additional keyword for this small a feature it’s probably not worth it.</div><div><br class=""></div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_default" style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)"><div class="gmail_default"><div class="gmail_default"><br class=""></div><div class="gmail_default"><br class=""></div><div class="gmail_default">Part II: change `repeat` statement ordering OR &nbsp;`while` statement modifier</div><div class="gmail_default">----------------------------------------------------------------------------------------</div><div class="gmail_default"><br class=""></div><div class="gmail_default">Idea #1:</div><div class="gmail_default"><br class=""></div><div class="gmail_default">Add a statement modifier to `while` that would ignore the `while` loop's condition only</div><div class="gmail_default">on the first run-through.</div><div class="gmail_default">Not too sure on the naming of the statement modifier but maybe something something like `after while foo &gt; bar { ... }`&nbsp;</div><div class="gmail_default"><br class=""></div><div class="gmail_default">`after` would signify that the while loops condition would be checked only after the first iteration.&nbsp;</div><div class="gmail_default"><br class=""></div><div class="gmail_default">Idea #2:</div><div class="gmail_default"><br class=""></div><div class="gmail_default">change `repeat { ... } while ...` to `repeat while ... { ... }` so that the loop condition can be seen upfront in long blocks,&nbsp;</div><div class="gmail_default">adding a `repeat` in front of the while loop would ensure that the loop runs once before evaluating the loop condition.</div><div class="gmail_default">This would essentially remove the repeat keyword and make it a statement modifier like the above written `after`.&nbsp;</div></div></div></div></div></blockquote><div><br class=""></div><div>I’m not really following you here.&nbsp;</div><div><br class=""></div><div>With regards to #1, the repeat-while/do-while style loops are very familiar to C programmers and programmers generally. I don’t think the "after" keyword would serve to reduce confusion.&nbsp;</div><div><br class=""></div><div>Same with #2. That syntax does seem to indicate in any way that the loop will run before the condition is checked. As far as I am aware, this runs counter to all while loop constructs in essentially all languages that have them.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_default" style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)"><div class="gmail_default"><div class="gmail_default"><br class=""></div><div class="gmail_default">Sorry for dragging this out a little after all the great feedback but does either idea have any appeal to the Swift community?</div><div class="gmail_default"><br class=""></div><div class="gmail_default">Thanks!</div><div class="gmail_default"><br class=""></div><div class="gmail_default">- Nick&nbsp;</div><div class="gmail_default"><br class=""></div></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif" class=""><br class=""></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif" class="">&nbsp;</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif" class=""><br class=""></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif" class="">&nbsp;</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif" class=""><br class=""></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif" class="">&nbsp;</div><div class="gmail_default"><br class=""></div><div class="gmail_default"><br class=""></div><div class="gmail_default"><br class=""></div><div class="gmail_extra" style="color:rgb(34,34,34);font-family:arial,sans-serif"><br clear="all" class=""><div class=""><div class="gmail_signature"><div dir="ltr" class=""><br class=""><div class="">All the best,</div><div class=""><br class=""></div><div class="">Nicholas</div><div class=""><br class=""></div><div class="">Linked in:</div><div class=""><font size="2" class=""><a href="http://lnkd.in/328U22" target="_blank" class="">http://lnkd.in/328U22</a></font><br class=""></div><div class=""><br class=""></div></div></div></div><br class=""><div class="gmail_quote">On Tue, May 10, 2016 at 4:39 PM, Xiaodi Wu&nbsp;<span dir="ltr" class="">&lt;<a href="mailto:xiaodi.wu@gmail.com" target="_blank" class="">xiaodi.wu@gmail.com</a>&gt;</span>&nbsp;wrote:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><span class="">On Tue, May 10, 2016 at 2:27 AM, Nicholas Maccharoli via swift-evolution&nbsp;<span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span>&nbsp;wrote:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr" class=""><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class="">​Swift Evolution ​Community,</div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class=""><br class=""></div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class="">Currently writing an infinite loop in swift looks either something like this:</div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class=""><br class=""></div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class="">&nbsp; &nbsp; while true {</div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class="">&nbsp; &nbsp; &nbsp; &nbsp; if ... { break }</div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class="">&nbsp; &nbsp; &nbsp; &nbsp; //...</div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class="">&nbsp; &nbsp; }</div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class=""><br class=""></div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class="">Or this:</div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class=""><br class=""></div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class="">&nbsp; &nbsp; repeat {</div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class="">&nbsp; &nbsp; &nbsp; &nbsp; if ... { break }</div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class="">&nbsp; &nbsp; &nbsp; &nbsp; //...</div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class="">&nbsp; &nbsp; } while true</div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class=""><br class=""></div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class="">But I think it might be best to change the syntax / behaviour of `repeat` to loop&nbsp;</div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class="">indefinitely if no trailing while clause is present:</div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class=""><br class=""></div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class="">&nbsp; &nbsp; repeat {</div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class="">&nbsp; &nbsp; &nbsp; &nbsp; if ... { break }</div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class="">&nbsp; &nbsp; &nbsp; &nbsp; //...</div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class="">&nbsp; &nbsp; }</div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class=""><br class=""></div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class="">while still allowing a trailing `while` clause as in:</div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class=""><br class=""></div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class="">&nbsp; &nbsp; repeat {&nbsp;</div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class="">&nbsp; &nbsp; &nbsp; &nbsp; foo += bar</div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class="">&nbsp; &nbsp; } while foo.count &lt; limit&nbsp;</div></div></blockquote><div class="">&nbsp;</div></span><div class="">What is your motivation for this change?</div><span class=""><div class="">&nbsp;</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr" class=""><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class=""></div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class="">I also want to propose that it should be a compile time error to use single `Bool` constants as while loop conditions, so no more `while true { ... }` it would become `repeat { ... }`</div></div></blockquote><div class=""><br class=""></div></span><div class="">What problems are solved by forbidding `while true`?</div><div class="">&nbsp;</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class=""><div dir="ltr" class=""><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class="">I was thinking of drafting a short proposal if there was enough positive feedback.&nbsp;<br class=""></div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class=""><br class=""></div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class="">How does it sound?</div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class=""><br class=""></div><div style="font-family:'comic sans ms',sans-serif;color:rgb(39,78,19)" class="">- Nick&nbsp;</div></div><br class=""></span>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" target="_blank" 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=""><br class=""></blockquote></div><br class=""></div></div></blockquote></div></div></div></div><div class="gmail_extra"><br clear="all" class=""><div class=""><div class="gmail_signature"><div dir="ltr" class=""><br class=""><div class="">All the best,</div><div class=""><br class=""></div><div class="">Nicholas</div><div class=""><br class=""></div><div class="">Linked in:</div><div class=""><font size="2" class=""><a href="http://lnkd.in/328U22" target="_blank" class="">http://lnkd.in/328U22</a></font><br class=""></div><div class=""><br class=""></div></div></div></div>
<br class=""><div class="gmail_quote">On Wed, May 11, 2016 at 10:11 AM, Tyler Cloutier via swift-evolution <span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br class="">
&gt; On May 10, 2016, at 5:56 PM, Chris Lattner &lt;<a href="mailto:clattner@apple.com" class="">clattner@apple.com</a>&gt; wrote:<br class="">
&gt;<br class="">
&gt;<br class="">
&gt;&gt; On May 10, 2016, at 4:13 PM, Cole Campbell via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class="">
&gt;&gt;<br class="">
&gt;&gt; I agree that repeat { } is ambiguous because you have to look to the end for a while clause to determine if it's infinite or not.<br class="">
&gt;<br class="">
&gt; Right, this is the downside that I see with “repeat {}”.<br class="">
<br class="">
<br class="">
</span>Not to beat a dead horse, but isn’t this also true of<br class="">
<br class="">
repeat {<br class="">
<br class="">
} while true<br class="">
<br class="">
and<br class="">
<br class="">
while true {<br class="">
&nbsp; &nbsp;...<br class="">
&nbsp; &nbsp;...<br class="">
&nbsp; &nbsp;if condition {<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; break<br class="">
<span class="">&nbsp; &nbsp;}<br class="">
}<br class="">
<br class="">
&gt;<br class="">
&gt;&gt; while true { } is preferable in that regard, but a compromise that I saw mentioned is:<br class="">
&gt;&gt;<br class="">
&gt;&gt; repeat forever { }<br class="">
&gt;<br class="">
&gt; This would require taking “forever” as a keyword if we supported “repeat N {", something we wouldn’t want to do.<br class="">
&gt;<br class="">
&gt; Another option is to make it a statement modifier, which wouldn’t require taking it as a keyword (but also doesn’t read as well):<br class="">
&gt;<br class="">
&gt; forever repeat { }<br class="">
&gt;<br class="">
&gt;<br class="">
&gt; Personally, I don’t see this as a big enough improvement over “while true” to be worth introducing complexity for.<br class="">
&gt;<br class="">
<br class="">
</span>If you are referring to “forever", I also don’t think that adding a new keyword is an improvement over “while true”.<br class="">
<div class="HOEnZb"><div class="h5"><br class="">
&gt; -Chris<br class="">
<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="">
</div></div></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></body></html>