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

Xiaodi Wu xiaodi.wu at gmail.com
Fri Jun 10 13:41:19 CDT 2016

On Fri, Jun 10, 2016 at 1:14 PM, Ryan Lovelett <swift-dev at ryan.lovelett.me>

> @Xiaodi Wu a couple of times you've said things were "explicit" this or
> that.
> > * Swift is explicitly a C-family language. In most or all other
> C-family languages, for loop statements allow specification of conditions
> for exiting the loop but not for filtering. Therefore, Swift's use of
> `where` is unprecedented and needs to be learned anew by every user of
> Swift.
> > That is worrying if true, because it suggests that it's enabling
> 'dialects' of Swift, an explicit anti-goal of the language
> Though I've never read either of these before as being goals (or for that
> matter anti-goals). Perhaps I'm looking in the wrong places though. Can you
> please share these with me?

These have been gleaned from pronouncements from the core team here on this
list. Unfortunately, it's not easy to search the archives. I'll give one
example, but I've seen similar ideas repeated a few times. Obviously, they
take place in the context of discussions about other features that are not
exactly the same as this, so one can wonder how much they apply here. If
they were exactly parallel situations, we wouldn't be having this

Chris Lattner's response to a proposal to adopt some Python-like syntax
that you can use if you like, but don't have to if you don't (Dec. 6, 2015):

> We're not interested in fragmenting *Swift* into related-but-different
> *dialect*s.
> -Chris


In trying to track that information down I read over
> https://swift.org/about/ trying to find if I could glean any information
> about some guiding principles. When I stumbled upon this and wondered if
> anyone else would find it illuminating.
> From the "Features" section:
> > Fast and concise iteration over a range or collection
> Does this proposal enhance that feature? Does this proposal weaken that
> feature?
> I've thought about that for a little bit and I'm pretty sure that removing
> `where` from for in certainly does not enhance that feature from my
> perspective.

No, but I don't think it harms fast and concise iteration; hence, I argue
that `where` is redundant.

> If I understand everything this all started because `if` can no longer
> have `where`.  Following that and basing it completely on the example in
> this proposal (
> <https://gist.github.com/erica/dd5935eca0d5d06b046184f41d56dd04>
> https://gist.github.com/erica/dd5935eca0d5d06b046184f41d56dd04#confusion-of-use)
> it seems to me that the behavior of the `where` clause of the `while` was
> analogous to the now removed `if` behavior.
> Therefore, if we are going to remove something lets remove the `where`
> clause from `while`.

My understanding is that removal from `while` is also part of SE-0099 and
already approved.

> As is already correctly pointed out in the "confusion of use" section the
> outlier behavior was `for in`. We deprecated the `if` behavior because of
> [fill in the blank], forgive me I never read the arguments, if `while`
> works the same way why does it not logically follow that its `where` clause
> also be deprecated.
> With that as far as I'm concerned this proposal is just requesting the
> retirement of the `where` clause on the wrong loop structure. Of course
> more examples could change my mind.

I'll endeavor to change your mind :) FWIW, I'd be satisfied with reforming
instead of removing `where` if doing so can clarify its meaning.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160610/4ac0dbff/attachment.html>

More information about the swift-evolution mailing list