[swift-evolution] [swift-evolution-announce] [Review] SE-0099: Restructuring Condition Clauses

Xiaodi Wu xiaodi.wu at gmail.com
Tue May 31 15:31:16 CDT 2016


On Tue, May 31, 2016 at 3:16 PM, Brandon Knope <bknope at me.com> wrote:

> What is wrong with:
>
> if let x = x where x > 10, y != 5, let z = z where z != x
>
> Just as a contrived example?
>

Because any grammar that permits what you propose would necessarily permit:

```
if let x = x, x > 10, y != 5, let z = z, z != x
```

Thus, `where` becomes redundant, a vestigial stylistic flourish.


> Brandon
>
> On May 31, 2016, at 4:03 PM, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
>
> On Tue, May 31, 2016 at 2:59 PM, Brandon Knope <bknope at me.com> wrote:
>
>> Except "b" is the main focus of the where clause and b was just in the
>> preceding if condition.
>>
>> I feel like we are trying to find ways to break the current where clause
>> even though we've enjoyed it for almost a year now. I had no idea it was
>> problematic and restrictive. I thought it made its intent very
>> clear...leading to very readable code.
>>
>> Pretty soon almost every construct but conditionals will be allowed to
>> have where clauses, and THAT seems inconsistent to me.
>>
>> ...what exactly is the current problem? Can someone show me a real world
>> example?? I've already forgotten it in all of this discussion -_-
>>
>>
> The origin of the problem is a simple question: how does one test for
> something unrelated to the variable that's bound in an `if let` statement?
> The answer is: in today's Swift, any such test after the first `let` must
> come after `where`. This is problematic and restrictive because one is
> forced to imply a semantic relationship that doesn't exist.
>
>
>> Brandon
>>
>> On May 31, 2016, at 3:47 PM, Xiaodi Wu via swift-evolution <
>> swift-evolution at swift.org> wrote:
>>
>>
>>
>> On Tue, May 31, 2016 at 2:45 PM, Christopher Kornher via swift-evolution
>> <swift-evolution at swift.org> wrote:
>>
>>>
>>>> Not allowed:
>>>>>>>> let a = a
>>>> let b = b where b > 10 && a > 5
>>>>
>>>
>>> Why would this not be allowed by your rule? You're making use of `b` in
>>> your where clause. As I demonstrated above, essentially any assertion can
>>> be rewritten to work around your rule. In general:
>>>
>>>
>>> It is not allowed because  ‘a’ is defined in the line above. It must be
>>> defined in the ‘if let’ associated with the where in which it is mentioned.
>>>
>>
>> That's a much more restrictive where clause than you proposed earlier.
>> You'd not be able to write:
>>
>> ```
>> let b = b where b > anyOtherVariable
>> ```
>>
>> _______________________________________________
>> 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/20160531/42a10e2a/attachment.html>


More information about the swift-evolution mailing list