[swift-evolution] [DRAFT] Regularizing Where Grammar (was Re: Add a while clause to for loops)

L. Mihalkovic laurent.mihalkovic at gmail.com
Thu Jun 9 17:11:31 CDT 2016


> On Jun 9, 2016, at 11:37 PM, Erica Sadun via swift-evolution <swift-evolution at swift.org> wrote:
> 
>> On Jun 9, 2016, at 3:18 PM, Rob Norback <rnorback at gmail.com> wrote:
>> 
>> Def like this change, but Erica I'm wondering what changed your mind about the syntax since the last I read you still were concerned by the ambiguity between filtering and exiting.
> 
> My concerns remain. However, after going back and forth with Brent, 
> wux, and others, I think my concerns could be addressed in style guides 
> and linters[1]. This draft introduces a major consistency win, I get to rail 
> against actually using the feature when I publicly opine[2], but when 
> used it will be better. (I'm quite curious to see hear from someone on the 
> core team whether this change is practical and whether it improves parsing 
> or makes it harder from the compiler's point of view.)
> 
> In any case, I reserve the right to argue from several different points of 
> view[1, ibid] to see how well each suggestion works (and to hear the feedback 
> and opinions of others) before settling on anything. Until it's a pull request, it's 
> not fixed. And even then, I still want to listen to arguments.
> 
> -- Erica
> 
> [1] As the Italians say, "La donna è mobile", which translates to "women are furniture." Ask an Italian.

Poor Verdi... he wouldn't recognize his rigoletto in that 'new' light...

> [2] I find a `where`-less `for-in` loop with `guard` statements to read the most clearly and offer the most maintainable approach. My computation tests show that it is in the top efficiency group.
> [3] Nulla nota 3.
> 
> 
>> On Thu, Jun 9, 2016 at 1:54 PM Erica Sadun via swift-evolution <swift-evolution at swift.org> wrote:
>>>> On Jun 9, 2016, at 1:57 PM, Haravikk <swift-evolution at haravikk.me> wrote:
>>>> 
>>>> I think the idea here is for a change from the first to the second of:
>>>> 
>>>> 	for eachValue in theValues where eachValue.isOdd { … }
>>>> 	for eachValue where eachValue.isOdd in theValues { … }
>>>> 
>>>> I’m kind of split on this for a few reasons. The first is that it doesn’t ready quite as well plain like this, however I find it looks a bit better like:
>>>> 
>>>> 	for (eachValue where eachValue.isOdd) in theValues { … }
>>> 
>>> 
>>> for eachValue where eachValue.isOdd in theValues { ... }
>>> for case .Some(let value) where value > 5 in theValues { ... }
>>> 
>>> vs
>>> 
>>> for eachValue in theValues where eachValue.isOdd {...}
>>> for case .Some(let value) in theValues where value > 5 { ... }
>>> 
>>> It should be parseable without parens.
>>> 
>>> 
>>>> Just to clarify that what we’re looking for in theValues is “eachValue where eachValue.isOdd”, though I could probably learn to read it like this without parenthesis. That said, parenthesis lines up nicely with assignment of tuples like:
>>>> 
>>>> 	for (eachKey, eachValue where eachValue > 5) in theKeyValuePairs { … }
>>> 
>>> for (eachKey, eachValue) where eachValue > 5 in theKeyValuePairs {... }
>>> 
>>> The where clause is distinct from the pattern
>>> 
>>> -- E
>>> 
>>> 
>>> _______________________________________________
>>> swift-evolution mailing list
>>> swift-evolution at swift.org
>>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160610/6271b5b5/attachment.html>


More information about the swift-evolution mailing list