[swift-evolution] [Pitch] making where and , interchangeable in guard conditions.

Matthew Johnson matthew at anandabits.com
Fri May 20 13:12:02 CDT 2016


> On May 20, 2016, at 1:01 PM, Erica Sadun <erica at ericasadun.com> wrote:
> 
> 
>> On May 20, 2016, at 11:53 AM, Matthew Johnson <matthew at anandabits.com <mailto:matthew at anandabits.com>> wrote:
>> I am less certain about allowing simple boolean expressions that are not introduced by the `where` keyword (excepting the first one which is introduced with the `guard` keyword).  I think this is a separate question that should receive independent consideration.  I think a reasonable argument can be made both ways.  
> 
> That's kind of the heart of the matter.
> 
> There's an assumption that guard statements are:
> 
> `guard` (conjoined boolean tests) | (conjoined boolean tests,)? (pattern | binding (where boolean)?, )+ else {...}
> 
> Right? (Except I couldn't figure out how to grammar out the final comma,) I'm suggesting:
> 
> `guard` ((boolean | (pattern | binding (where boolean)?)),)+ else {...}
> 
> instead. (And ditto about final comma) This promotes boolean statements to the same standing, so they're not limited to the start of the guard statement or syntactically tied to a pattern/binding where there may be no semantic basis.

Yep, I know.  I’m agreeing with breaking the syntactic tie to pattern binding, just questioning whether we should drop the need to introduce subsequent ones with `where`.  I am on the fence as to which is more readable and interested in hearing discussion about that.

This is what it would look like if drop the requirement that they be tied to a pattern binding but we require `where` on subsequent boolean expressions (meaning each clause is introduced with a keyword.

`guard` (boolean,)? (((where boolean) | (pattern | binding (where boolean)?)),)+ else {…}

We could also do this if we wanted to allow all boolean expressions, even the first, to be introduced with `where` to support consistent formatting of all clauses in a multi-line construct like the ones in your example.

`guard` (where? boolean,)? (((where boolean) | (pattern | binding (where boolean)?)),)+ else {...}

> 
> -- E
> 
> 
> 
> 
> 
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160520/c74bcb02/attachment.html>


More information about the swift-evolution mailing list