[swift-evolution] [Pitch] Retiring `where` from for-in loops

Xiaodi Wu xiaodi.wu at gmail.com
Fri Jun 10 11:30:24 CDT 2016


On Fri, Jun 10, 2016 at 7:45 AM, Dany St-Amant <dsa.mls at icloud.com> wrote:

>
> > Le 10 juin 2016 à 02:25, Xiaodi Wu <xiaodi.wu at gmail.com> a écrit :
> >
> > * The word "where" does not consistently imply `break` or `continue`. In
> current Swift, `where` implies `break` in the context of a `while` loop and
> `continue` in the context of a `for` loop. Some users intuitively guess the
> correct meaning in each context, while others guess the wrong meaning.
> Therefore, the only way to learn for sure what `where` means in any context
> is to read the rulebook. That, by definition, means that this is
> unintuitive.
>
> An example here would have help... I had trouble visualizing the 'where'
> with 'while'. A quick example I was able to conjure is:
>
> var array =  [9,8,7,6,5,4,3,2,1]
> while let x = are.popLast() where x < 5 { print(x) }
> print(array)
>
> What? 'array' is not empty at the end. I admit, I was surprised by the
> result at first. The confusion here is not that 'where' in 'for' behave
> like 'continue' and 'where' in 'while' act like a 'break', as the later
> doesn't conceptually exist. The later concept is using 'where' as a
> conditional binding in a 'while' causes a failure of the bind and thus a
> 'break' out of the loop. With the acceptance of the revised SE-0099, the
> 'while' can no longer appear to be using 'where', thus removing this
> confusion.
>

I'm relieved that it's been addressed. There was no small amount of
contention that `where` in `while` loops was stylistically delightful and
ought to remain, but I think you see why at least on first sight it is
rather alarming.


>
> Dany
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160610/1c4f9be0/attachment.html>


More information about the swift-evolution mailing list