[swift-evolution] [Review] SE-0105: Removing Where Clauses from For-In Loops

Dany St-Amant dsa.mls at icloud.com
Thu Jun 23 21:05:46 CDT 2016

> Le 23 juin 2016 à 00:12, Chris Lattner via swift-evolution <swift-evolution at swift.org> a écrit :
> Hello Swift community,
> The review of "SE-0105: Removing Where Clauses from For-In Loops" begins now and runs through June 29. The proposal is available here:
>    https://github.com/apple/swift-evolution/blob/master/proposals/0105-remove-where-from-forin-loops.md

>    * What is your evaluation of the proposal?


The 'where' is a nice sugar for people familiar with SQL but doesn't seem to hold its ground. Without 'where' nor 'guard', something like:

for element in collection where condition(element) { doSomething(element) }

is/could be

for element in collection { if condition(element) { doSomething(element) } }

Beside the extra curly brace there isn't much difference in the clarity of the message, rendering the sugar not as sweet as it sound.

Also the 'where' is not available to the other loop structure: 'while', 'repeat', 'do'. For these one have to rely on 'if' and 'guard'. "Forcing" the use of 'if' and 'guard' in all loop structure would provide uniformity.

The fix-it should probably used the nested 'for { if { } }' as its the syntax matching more closely what was written, at the cost of one ident level, and missing an opportunity to advertise a usage of 'guard'

>    * Is the problem being addressed significant enough to warrant a change to Swift?

No, 'where' is not confusing; it's the 'while binding where' and the 'for .. In infiniteSequence where ..' which are.
Yes, 'where' (in 'for .. in') is pointless and if it did not currently exist would likely never be approved as an addition to the language due to its narrow field of operation.

>    * Does this proposal fit well with the feel and direction of Swift?

'for .. in .. where'
Has a Swift like syntax
Is a sugar with limited scope which doesn't pull its weight, so is not Swift like

>    * If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?

Never used 'where' attached to directly to a loop.
Extensive use of SQL-like queries.

>    * How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

Closely followed the thread as I originally feared the disappearance of this nice construct. Tried and failed to understand how the syntax can be seen as confusing.


More information about the swift-evolution mailing list