<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Jun 7, 2016 at 2:16 PM, Tim Vermeulen <span dir="ltr"><<a href="mailto:tvermeulen@me.com" target="_blank">tvermeulen@me.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">> The meaning of the proposed while is not at all a pair for where, since where clauses in while loops would do the same thing as while clauses in for loops. That's crazy.<br>
<br>
</span>It sounds crazy, but it’s the nature of the while loop. A where clause in a while loop also has a different result than a where clause in a for loop.<br></blockquote><div><br></div><div>I know. And SE-0099 proposed to eliminate it, and I am very supportive of that. For all of the reasons outlined in that conversation (including the different behaviors in while and for loops), I arrive at the conclusion that `where` is unsuitable for use in all condition statements and would support its complete elimination from the language.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class=""><br>
> filter() is and prefix(while:) will be available on all sequences. The for...in loop only traverses through sequences.<br>
><br>
> The meaning of the proposed while is not at all a pair for where, since where clauses in while loops would do the same thing as while clauses in for loops. That's crazy.<br>
><br>
</span><div><div class="h5">> On Tue, Jun 7, 2016 at 06:20 Vladimir.S via swift-evolution<<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>(mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>)>wrote:<br>
> > My +1 to the proposal and for Charlie's opinion. I believe `while` in `for`<br>
> > loop would be very handy and helpful in some situations, it is a pair for<br>
> > existed `where`, its meaning is obvious, and its existence can't depend on<br>
> > existence of any method in collections. I'd like to see a formal proposal<br>
> > for this feature.<br>
> ><br>
> > On 07.06.2016 8:18, Charlie Monroe via swift-evolution wrote:<br>
> > >I strongly disagree.<br>
> > ><br>
> > >Exchanging<br>
> > ><br>
> > >for result in results where result.value != .Warning while result.value !=<br>
> > >.Error {<br>
> > >/// ...<br>
> > >}<br>
> > ><br>
> > >for either<br>
> > ><br>
> > >for result in results.filter({ $0.value != .Warning }).prefix(while: {<br>
> > >$0.value != .Error })) {<br>
> > >/// ...<br>
> > >}<br>
> > ><br>
> > >or<br>
> > ><br>
> > >for result in results {<br>
> > >if result.value == .Warning { continue }<br>
> > >if result.value == .Error { break }<br>
> > ><br>
> > >/// ...<br>
> > >}<br>
> > ><br>
> > >Seems like an absolute step back. Not to mention filter(_:) doesn't return<br>
> > >a lazy collection, but will recreate it, while the `where` will do<br>
> > >on-the-fly check.<br>
> > ><br>
> > >>On Jun 7, 2016, at 1:34 AM, Xiaodi Wu via swift-evolution<br>
</div></div>> > >><<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>(mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>)<mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>>wrote:<br>
<span class="">> > >><br>
> > >>Personally, given this discussion and the one about `where` in if and<br>
> > >>while statements, I would not be opposed to elimination of `where` in<br>
> > >>control statements altogether.<br>
> > >><br>
> > >>My reasoning would be that words like filter and prefix unambiguously<br>
> > >>indicate what happens to elements of a sequence for which the predicate<br>
> > >>returns false, whereas words like where and while are ambiguous.<br>
> > >><br>
</span>> > >>On Mon, Jun 6, 2016 at 17:52 Tim Vermeulen<<a href="mailto:tvermeulen@me.com">tvermeulen@me.com</a>(mailto:<a href="mailto:tvermeulen@me.com">tvermeulen@me.com</a>)<br>
<span class="">> > >><mailto:<a href="mailto:tvermeulen@me.com">tvermeulen@me.com</a>>>wrote:<br>
> > >><br>
> > >>I didn’t mean we should really get rid of the `where` clause, it’s<br>
> > >>great. I guess the point I was trying to make is that we can use a<br>
> > >>`where` clause with a `for` loop in Swift, despite the existence of<br>
> > >>the `filter` method. So despite `prefix(while:)` in Swift 3, there<br>
> > >>might be room for a `while` clause. I think it makes the code a lot<br>
> > >>more readable, much like how `where` can make a `for` loop a lot more<br>
> > >>readable than using `filter`.<br>
> > >><br>
> > >>>The burden of proof for adding new features is different from that<br>
> > >>for taking away existing features.<br>
> > >>><br>
> > >>>If a feature doesn't yet exist, a successful proposal will show how<br>
> > >>it provides additional and non-trivial utility. If a feature already<br>
> > >>exists, a successful proposal to remove it will show how it is<br>
> > >>harmful to the language or contrary to the direction in which it is<br>
> > >>evolving.<br>
> > >>><br>
</span>> > >>>On Mon, Jun 6, 2016 at 15:38 Tim Vermeulen<<a href="mailto:tvermeulen@me.com">tvermeulen@me.com</a>(mailto:<a href="mailto:tvermeulen@me.com">tvermeulen@me.com</a>)<br>
<span class="">> > >><mailto:<a href="mailto:tvermeulen@me.com">tvermeulen@me.com</a>>(mailto:<a href="mailto:tvermeulen@me.com">tvermeulen@me.com</a><br>
> > >><mailto:<a href="mailto:tvermeulen@me.com">tvermeulen@me.com</a>>)>wrote:<br>
> > >>>>The functionality of the `where` clause in `for` loops also<br>
> > >>already can be mimicked using `filter`. Wouldn’t we have to get ride<br>
> > >>of the `where` clause by that logic?<br>
> > >>>><br>
> > >>>>>The functionality being asked for here is already accepted for<br>
> > >>inclusion to Swift as a method on Sequence named `prefix(while:)`<br>
> > >>(SE-0045):<br>
> > >>>>><br>
> > >>>>>`for element in array.prefix(while: { someCondition($0) }) { ... }`<br>
> > >>>>>On Mon, Jun 6, 2016 at 14:31 T.J. Usiyan via<br>
</span>> > >>swift-evolution<<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>(mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>)<br>
<span class="">> > >><mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>(mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
> > >><mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>)(mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
> > >><mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>)>wrote:<br>
> > >>>>>>(As I said, I can live with `while`. I am simply presenting a<br>
> > >>potential point of confusion.)<br>
> > >>>>>>You aren't evaluating the statements in the loop 'while' the<br>
> > >>condition isn't met. The first time that the condition isn't met,<br>
> > >>evaluation of the loop stops. I get that this is technically true for<br>
> > >>the `while` construct but I suggest that the only reason that it<br>
> > >>works there is that 'stopping the first time that the condition isn't<br>
> > >>met' *is* the construct. Here, we have a loop that we execute for<br>
> > >>each thing and we're tacking on/intermingling the `while` construct.<br>
> > >>>>>><br>
> > >>>>>><br>
> > >>>>>><br>
> > >>>>>>On Mon, Jun 6, 2016 at 2:19 PM, Thorsten<br>
</span>> > >>Seitz<<a href="mailto:tseitz42@icloud.com">tseitz42@icloud.com</a>(mailto:<a href="mailto:tseitz42@icloud.com">tseitz42@icloud.com</a>)<br>
<span class="">> > >><mailto:<a href="mailto:tseitz42@icloud.com">tseitz42@icloud.com</a>>(mailto:<a href="mailto:tseitz42@icloud.com">tseitz42@icloud.com</a><br>
> > >><mailto:<a href="mailto:tseitz42@icloud.com">tseitz42@icloud.com</a>>)(mailto:<a href="mailto:tseitz42@icloud.com">tseitz42@icloud.com</a><br>
> > >><mailto:<a href="mailto:tseitz42@icloud.com">tseitz42@icloud.com</a>>)>wrote:<br>
> > >>>>>>><br>
> > >>>>>>>>Am 06.06.2016 um 19:43 schrieb Tim Vermeulen via<br>
</span>> > >>swift-evolution<<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>(mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>)<br>
<span class="">> > >><mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>(mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
> > >><mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>)(mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
> > >><mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>)>:<br>
> > >>>>>>>><br>
> > >>>>>>>>I also considered `until`, but it would be a bit confusing<br>
> > >>that `where` makes sure a condition is met, while `until` makes sure<br>
> > >>the condition isn’t met. I think `while` makes more sense because it<br>
> > >>corresponds to `break` in the same way that `where` corresponds to<br>
> > >>`continue`.<br>
> > >>>>>>><br>
> > >>>>>>>That's a good argument! The only drawback is that `while` and<br>
> > >>`where` look quite similar at a glance.<br>
> > >>>>>>><br>
> > >>>>>>>-Thorsten<br>
> > >>>>>>><br>
> > >>>>>>>><br>
> > >>>>>>>>>`while`, to me, actually reads like it should do what<br>
> > >>`where` does.<br>
> > >>>>>>>><br>
> > >>>>>>>>To me, `while` reads like it should stop the loop once the<br>
> > >>condition isn’t met, just like in a while loop.<br>
> > >>>>>>>><br>
> > >>>>>>>>>I hadn't thought about `while` in this regard but wouldn't<br>
> > >>`until` make more sense? `while`, to me, actually reads like it<br>
> > >>should do what `where` does. In any case, whether it is `while` or<br>
> > >>`where`, this seems like a reasonable feature in my opinion.<br>
> > >>>>>>>>><br>
> > >>>>>>>>>TJ<br>
> > >>>>>>>>><br>
> > >>>>>>>>>On Mon, Jun 6, 2016 at 5:15 AM, Tim Vermeulen via<br>
</span>> > >>swift-evolution<<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>(mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>)<br>
<div><div class="h5">> > >><mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>(mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
> > >><mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>)(mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
> > >><mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>)(mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
> > >><mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>)>wrote:<br>
> > >>>>>>>>>>We can already use a where clause in a for loop like this:<br>
> > >>>>>>>>>><br>
> > >>>>>>>>>>for element in array where someCondition(element) {<br>
> > >>>>>>>>>>// …<br>
> > >>>>>>>>>>}<br>
> > >>>>>>>>>><br>
> > >>>>>>>>>>which basically acts like<br>
> > >>>>>>>>>><br>
> > >>>>>>>>>>for element in array {<br>
> > >>>>>>>>>>guard someCondition(element) else { continue }<br>
> > >>>>>>>>>>// …<br>
> > >>>>>>>>>>}<br>
> > >>>>>>>>>><br>
> > >>>>>>>>>>Sometimes you want to break out of the loop when the<br>
> > >>condition isn’t met instead. I propose a while clause:<br>
> > >>>>>>>>>><br>
> > >>>>>>>>>>for element in array while someCondition(element) {<br>
> > >>>>>>>>>>// …<br>
> > >>>>>>>>>>}<br>
> > >>>>>>>>>><br>
> > >>>>>>>>>>which would be syntactic sugar for<br>
> > >>>>>>>>>><br>
> > >>>>>>>>>>for element in array {<br>
> > >>>>>>>>>>guard someCondition(element) else { break }<br>
> > >>>>>>>>>>…<br>
> > >>>>>>>>>>}<br>
> > >>>>>>>>>><br>
> > >>>>>>>>>>I can see this particularly being useful if we have a<br>
> > >>sorted array and we already know that once the condition isn’t met,<br>
> > >>it won’t be met either for subsequent elements. Another use case<br>
> > >>could be an infinite sequence that we want to cut off somewhere<br>
> > >>(which is simply not possible using a where clause).<br>
> > >>>>>>>>>>_______________________________________________<br>
> > >>>>>>>>>>swift-evolution mailing list<br>
</div></div>> > >>>>>>>>>><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>(mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>)<br>
<span class="">> > >><mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>(mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
> > >><mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>)(mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
> > >><mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>)(mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
> > >><mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>)<br>
> > >>>>>>>>>><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
> > >>>>>>>>_______________________________________________<br>
> > >>>>>>>>swift-evolution mailing list<br>
</span>> > >>>>>>>><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>(mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>)<br>
<span class="">> > >><mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>(mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
> > >><mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>)(mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
> > >><mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>)<br>
> > >>>>>>>><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
> > >>>>>><br>
> > >>>>>>_______________________________________________<br>
> > >>>>>>swift-evolution mailing list<br>
</span>> > >>>>>><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>(mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>)<br>
<span class="">> > >><mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>(mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
> > >><mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>)(mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
> > >><mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>)<br>
> > >>>>>><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
> > >>>>><br>
> > >>>>><br>
> > >>>>>_______________________________________________<br>
> > >>>swift-evolution mailing list<br>
</span>> > >>><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>(mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>)<mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>><br>
<span class="">> > >>><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
> > >>><br>
> > >>><br>
> > >>><br>
> > >><br>
> > >>_______________________________________________<br>
> > >>swift-evolution mailing list<br>
</span>> > >><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>(mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>)<mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>><br>
<span class="">> > >><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
> > ><br>
> > ><br>
> > ><br>
> > >_______________________________________________<br>
> > >swift-evolution mailing list<br>
</span>> > ><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>(mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>)<br>
<span class="">> > ><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
> > ><br>
> > _______________________________________________<br>
> > swift-evolution mailing list<br>
</span>> > <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>(mailto:<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>)<br>
> > <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
><br>
><br>
> </blockquote></div><br></div></div>