[swift-evolution] Rekindling: "Extending declaration scope to condition for `repeat { } while ()"

Michael Savich savichmichael at icloud.com
Tue Jun 6 06:10:44 CDT 2017


Oh, I admit I had never realized do could be used outside of an error handling context. Yeah, then I would agree then this change is probably unnecessary. Looking at the Swift guidebook it may be a good idea make it more explicit that the do statement is meant to be used for things other than do-try-catch, assuming that this is an intended use case. But I digress, as that would be a discussion for another time/thread.

Sent from my Mac

> On Jun 6, 2017, at 6:52 AM, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
> 
> If I recall correctly, it was discussed during a time when additive proposals were not in scope, so it could not be proposed. Since at the moment we are currently between Swift 4 and Swift 5 evolution, the topic is not in scope either.
> 
> With respect to the idea itself, Taras's post--which appears to be the last on the subject--is useful to re-consider here:
> 
> > This is definitively something very useful but it also introduces a strong asymmetry into Swift statements. In all control-flow statements, the condition is part of the outer scope. Or, to be more precise, its part of an intermediate scope between the outer and the inner scope (as you can declare variables in the condition which are invisible to the outer scope but visible to the inner scope). Your suggestion essentially moves the condition of repeat {} while () to the inner scope. I think that the more complex semantics is not worth the change. 
> 
> I recall being initially in favor of the idea myself. However, any sort of change of syntax is a big deal; it will prompt a lot of bikeshedding, and it will require engineering effort to implement that is sorely needed elsewhere. With time, I question whether this idea meets the necessarily high bar for changing syntax; indeed if the motivation is to keep something from the outer scope, it's trivial to make this happen with an outer `do`:
> 
> ```
> do {
>   var i = 0
>   repeat {
>     // ...
>   } while i < 42
> }
> ```
> 
> 
> On Tue, Jun 6, 2017 at 4:05 AM, Michael Savich via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> It recently occurred to me how nice it would be to be if we could avoid declaring variables outside of loops that are only used inside them. I used google’s site specific search (is that the canon way to search swift-evo?) and only found one thread about this, (https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160718/024657.html <https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160718/024657.html>) where from what I could see it got a positive reception.
> 
> It would be a special case though, and within an unrelated thread I saw this suggestion (https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151207/001201.html <https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151207/001201.html>) of letting you write a variable declaration in between the repeat keyword and the opening bracket. Personally I prefer this syntax.
> 
> Regardless, I’m wondering what happened to this thread? Is there a reason it didn’t get proposed? If the answer is that the discussion simply died down it may be worth revisiting it.
> 
> Sent from my Mac
> 
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170606/bd7b3871/attachment.html>


More information about the swift-evolution mailing list