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

Brandon Knope bknope at me.com
Tue May 31 15:11:17 CDT 2016


The y == y I presume is to get around this requirement by reintroducing a variable in the previous part of the conditional to be able to refer to other variables. 

x > z isn't allowed, but y == y && x > z would be because it's using y. 

I'm not convinced anyone would do this when they could just && x > z anyways 

Brandon 

> On May 31, 2016, at 4:06 PM, Christopher Kornher via swift-evolution <swift-evolution at swift.org> wrote:
> 
> I should have left the entire context in my reply.
> 
> 
>> On May 31, 2016, at 1:59 PM, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
>> 
>>> On Tue, May 31, 2016 at 2:51 PM, Christopher Kornher via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>>> 
>>>> On May 31, 2016, at 1:47 PM, Xiaodi Wu <xiaodi.wu at gmail.com> 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
>>>> ```
>>> 
>>> 
>>> The definition is not a formal one, but that was the intent.
>>> 
>>> ```
>>> let b = b where b > anyOtherVariable
>>> ```
>>> is legal as long as `anyOtherVariable` is not defined within the entire condition clause
>> 
>> 
>> You can propose that rule, but it doesn't solve the issue. If, today, I've got
>> 
>> ```
>> let x = 1
>> let y: Int? = 2
>> let z = 3
>> 
>> if let y = y where x < z {
>>   // do stuff
>> }
>> ```
>> 
>> your rule simply forces
>> 
>> ```
>> if let y = y where y == y && x < z {
>>   // do stuff
>> }
>> ```
>> 
>> The point is, the semantic relationship between what comes before and after `where` exists in the mind of the human reader only.
> 
> I meant to add that all boolean expressions after the where must use one of the constants defined in the associated `if let` so the `&& x < z` would not be allowed.
> 
> I don’t understand the 'y == y’ in your example
> 
> 
> _______________________________________________
> 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/e9b63138/attachment.html>


More information about the swift-evolution mailing list