[swift-evolution] Change `repeat` to loop indefinitely if no while clause is present
Xiaodi Wu
xiaodi.wu at gmail.com
Tue May 10 18:19:20 CDT 2016
On Tue, May 10, 2016 at 6:02 PM, Tyler Cloutier <cloutiertyler at aol.com>
wrote:
Let me be explicit about how the two ideas compare.
> I’d also like to point out Chris’ comments on the
>>
>> repeat X {
>>
>> }
>>
>> discussion.
>>
>> “
>>
>> 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.
>>
>>
Repeating N times is a simple case, and `repeat N { }` makes it simple.
Repeating an indefinite number of times is not really a simple case--at
least, it's not the same case--and it's not even profitably usable until a
beginner has mastered another concept, namely `break`.
> + Even if you aren’t familiar with it, you can tell at first glance what the behavior is.
>>
>>
As I've mentioned above and Cole has just reinforced, with this proposal,
you can't tell at first glance what the behavior of `repeat {` is until you
read the end brace--even if you *are* familiar with it. By contrast,
`repeat N { }` is immediately understood, whether or not you're familiar
with it.
> - It is “just syntactic sugar”, which makes the language more complex.
>>
>>
Whether you naively compare letters saved or concepts invoked, `repeat N {
}` is very sweet sugar in comparison to `for _ in 0..<N { }`, but `repeat {
}` is not very sweet sugar in comparison to `while true { }`.
> - It is a very narrow feature that is useful in few practical situations.
>>
>>
Here, `repeat N { }` can be used for any value N, but `repeat { }` is
useful only for saving four letters from `while true { }`.
>
>> -Chris
>>
>> “
>>
>> 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.
>>
>
> For the reasons I outlined above, I'd be +1 for `repeat N` and -1 for this
> case.
>
>
> That’s fair enough. :)
>
> But surely you’ll admit that if
>
> repeat N {
>
> }
>
> was valid, then repeat { } follows as the logical repeat indefinitely
> syntax, no?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160510/bf3dc05c/attachment.html>
More information about the swift-evolution
mailing list