<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div></div><div>I agree that <span style="background-color: rgba(255, 255, 255, 0);">repeat { } is ambiguous because you have to look to the end for a while clause to determine if it's infinite or not. while true { } is preferable in that regard, but a compromise that I saw mentioned is:</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">repeat forever { }</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div>That is immediately clear that it is infinite like while true { } but reads better in English. And it's a nice extension of repeat N { }, which is something I wouldn't mind seeing being added to the language.</div><div><br></div><div>So +1 for repeat N { }, +1 for repeat forever { }, -1 for repeat { }.</div><div><br>On May 10, 2016, at 6:02 PM, Tyler Cloutier via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8"><br class=""><div><blockquote type="cite" class=""><div class="">On May 10, 2016, at 3:59 PM, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_extra"><div class="gmail_quote">On Tue, May 10, 2016 at 5:56 PM, Tyler Cloutier<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:cloutiertyler@aol.com" target="_blank" class="">cloutiertyler@aol.com</a>></span><span class="Apple-converted-space"> </span>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 style="word-wrap: break-word;" class=""><br class=""><div class=""><blockquote type="cite" class=""><span class=""><div class="">On May 10, 2016, at 3:13 PM, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" target="_blank" class="">xiaodi.wu@gmail.com</a>> wrote:</div><br class=""></span><span class=""><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><div class="gmail_extra"><div class="gmail_quote">On Tue, May 10, 2016 at 3:30 PM, Tyler Cloutier via swift-evolution<span class=""> </span><span dir="ltr" class=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>></span><span class=""> </span>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 style="word-wrap: break-word;" class="">I’d actually say that I’m strongly in favor of allowing just a repeat keyword, although I wouldn’t support making 'while true’.<div class=""><br class=""></div><div class="">Firstly it reduces clutter</div></div></blockquote><div class=""><br class=""></div><div class="">Can you explain what clutter you see? Unless I misunderstand what you're referring to, reducing the 10 letters in `while true` to the six letters in `repeat` is hardly "reducing clutter."<br class=""></div><div class=""> </div><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 style="word-wrap: break-word;" class=""><div class="">and makes it very clear that the the code is just supposed to repeat.</div></div></blockquote><div class=""><br class=""></div><div class="">I disagree here also. It is not very clear at all that the code is supposed to repeat indefinitely, not to any audience.</div><div class=""><br class=""></div><div class="">First, it would not be clear to users who are experienced in Swift and aware of this proposal. Code is meant to be read, and allowing the omission of a trailing clause to produce two very different behaviors means that it is not clear what `repeat {` means until you encounter the closing brace and check for what follows. Moreover, what follows could be the keyword `while` on the following line, and in that case you cannot know whether the expression that follows `while` is the beginning of a new while loop until you encounter or don't encounter a new opening brace. By contrast, `while true {` cannot be anything other than the beginning of an infinite loop. You already know that fact after reading 12 letters.<br class=""></div><div class=""><br class=""></div><div class="">Second, it would not be clear to users migrating from another C-family language. `while true { }` is immediately understood by users of any other related language.</div><div class=""><br class=""></div><div class="">Third, it would not be clear based on a knowledge of English. In common use, "repeat" does not mean repeat forever; it means to repeat once (i.e. do something twice). If I ask you to repeat something you just said, I should hope that you do not keep reciting it over and over until I tell you to stop.</div><div class=""> </div><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 style="word-wrap: break-word;" class=""><div class="">Secondly it’s a very simple way of introducing new programmers to loops. It’s IMHO more clear to a new programmer that repeat will just repeat indefinitely vs while true.</div></div></blockquote><div class=""><br class=""></div><div class="">I can speak to this a little bit, having introduced a new programmer to loops very recently and having done so in the past as well. I have not encountered anyone who has trouble with the *concept* of looping--i.e. the idea that the same code can be run over and over.</div><div class=""><br class=""></div><div class="">Where things get tricky is the difficulty of mastering the syntax of the while loop and, more problematic, the syntax of the classic for;; loop. Introducing a simple way to make something repeat forever does not solve this learning hurdle, because students will continue to have to contend with these other types of loops in order to be productive in the language. A special syntax for repeating forever is especially unhelpful because it is just functional enough that a discouraged student may choose to avoid learning other types of loops and instead combine the infinite loop with if, continue, and break.</div></div></div></div></div></span></blockquote><div class=""><br class=""></div><div class="">I’d also like to point out Chris’ comments on the </div><div class=""><br class=""></div><div class="">repeat X {</div><div class=""><br class=""></div><div class="">}</div><div class=""><br class=""></div><div class="">discussion.</div><div class=""><br class=""></div><div class="">“</div><div class=""><pre style="white-space: pre-wrap; background-color: rgb(255, 255, 255);" class="">This is a very valid use case.
FWIW, “repeat N {}” was originally designed and scoped into the Swift 2 implementation of the feature, but was cut due to schedule limitations. There is precedent for this sort of feature in many teaching oriented languages (e.g. Logo).
I’d say that the pro’s and con’s of this are:
+ Makes a simple case very simple, particularly important in teaching.
+ Even if you aren’t familiar with it, you can tell at first glance what the behavior is.
- It is “just syntactic sugar”, which makes the language more complex.
- It is a very narrow feature that is useful in few practical situations.
-Chris</pre><div class="">“</div><div class=""><br class=""></div><div class="">In this case, I would say it’s not making the language any more complex given that repeat-while is a current construct. Admittedly it is a very narrow feature, but it’s also a small one.</div></div></div></div></blockquote><div class=""><br class=""></div><div class="">For the reasons I outlined above, I'd be +1 for `repeat N` and -1 for this case.</div><div class=""><br class=""></div></div></div></div></div></blockquote><div><br class=""></div><div>That’s fair enough. :)</div><div><br class=""></div><div>But surely you’ll admit that if </div><div><br class=""></div><div>repeat N {</div><div><br class=""></div><div>}</div><div><br class=""></div><div>was valid, then repeat { } follows as the logical repeat indefinitely syntax, no?</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""> </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 style="word-wrap: break-word;" class=""><div class=""><div class=""><div class="h5"><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""> </div><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 style="word-wrap: break-word;" class=""><div class="">Lastly, this isn’t the first time this has been brought up on this list and there was previously discussion about the fact that when people see the repeat keyword that it should naturally repeat indefinitely unless a where clause is specified.</div></div></blockquote><div class=""><br class=""></div><div class="">I do believe that this is the first time this suggestion has been introduced to the list. I do not recall any previous discussion focused on infinite loops; they have been about repeating a finite number of times, using proposed syntax such as `repeat 3 times { }` or variations on that theme.</div><div class=""> </div><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 style="word-wrap: break-word;" class=""><div class=""></div><div class="">I also think the concern that an accidental infinite loop is any greater than it is currently.</div></div></blockquote><div class=""><br class=""></div><div class="">Code gets refactored and edited. We're discussing on another thread changing the rules about dangling commas in parameter lists for that very reason. If you try to move a block of code with a repeat...while loop but accidentally leave behind the last line, this syntax will cause you grief.</div><div class=""> </div><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 style="word-wrap: break-word;" class=""><div class="">Tyler</div><div class=""><div class=""><div class=""><div class=""><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On May 10, 2016, at 1:09 PM, Erica Sadun via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:</div><br class=""><div class=""><div style="word-wrap: break-word;" class=""><div class="">I do not see sufficiently measurable benefits to this proposal to add it to the language. </div><div class="">It's easy enough to roll your own `repeatForever` function with trailing closure.</div><div class=""><br class=""></div><div class="">I also want to thank you for bring it up on-list. Not every idea is right for Swift but it's</div><div class="">always refreshing to see innovative thoughts added to the discussion. Please do not be </div><div class="">discouraged by the generally negative feedback on this particular idea.</div><div class=""><br class=""></div><div class="">-- Erica</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div class="">On May 10, 2016, at 1:27 AM, Nicholas Maccharoli via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:</div><br class=""><div class=""><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=""> <span class=""> </span>while true {</div><div style="font-family: 'comic sans ms', sans-serif; color: rgb(39, 78, 19);" class=""> <span class=""> </span>if ... { break }</div><div style="font-family: 'comic sans ms', sans-serif; color: rgb(39, 78, 19);" class=""> <span class=""> </span>//...</div><div style="font-family: 'comic sans ms', sans-serif; color: rgb(39, 78, 19);" class=""> <span class=""> </span>}</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=""> <span class=""> </span>repeat {</div><div style="font-family: 'comic sans ms', sans-serif; color: rgb(39, 78, 19);" class=""> <span class=""> </span>if ... { break }</div><div style="font-family: 'comic sans ms', sans-serif; color: rgb(39, 78, 19);" class=""> <span class=""> </span>//...</div><div style="font-family: 'comic sans ms', sans-serif; color: rgb(39, 78, 19);" class=""> <span class=""> </span>} 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 </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=""> <span class=""> </span>repeat {</div><div style="font-family: 'comic sans ms', sans-serif; color: rgb(39, 78, 19);" class=""> <span class=""> </span>if ... { break }</div><div style="font-family: 'comic sans ms', sans-serif; color: rgb(39, 78, 19);" class=""> <span class=""> </span>//...</div><div style="font-family: 'comic sans ms', sans-serif; color: rgb(39, 78, 19);" class=""> <span class=""> </span>}</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=""> <span class=""> </span>repeat { </div><div style="font-family: 'comic sans ms', sans-serif; color: rgb(39, 78, 19);" class=""> <span class=""> </span>foo += bar</div><div style="font-family: 'comic sans ms', sans-serif; color: rgb(39, 78, 19);" class=""> <span class=""> </span>} while foo.count < limit </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="">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 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="">I was thinking of drafting a short proposal if there was enough positive feedback. </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 </div></div>_______________________________________________<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" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div>_______________________________________________<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" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div></div></div></div></div></div><br class="">_______________________________________________<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></blockquote></div></div></div></div></blockquote></div></div></div></div></blockquote></div></div></div></div></blockquote></div><br class=""></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>