[swift-evolution] if case 1, 2, 3 = x { ... } results in error in swift 2

Kevin Ballard kevin at sb.org
Thu Dec 3 19:04:41 CST 2015


Ah, so you're proposing that the syntax be changed, rather than merely
asking why the code doesn't work? That makes sense.

As for why it's not supported now, I don't know. Maybe there's some
syntactic ambiguity in allowing it? Or maybe there was just concern
about it being confusing. Hopefully someone involved in the
implementation of it can answer this.

-Kevin Ballard

On Thu, Dec 3, 2015, at 04:55 PM, Amir Michail wrote:
> 
> > On Dec 3, 2015, at 7:51 PM, Kevin Ballard <kevin at sb.org> wrote:
> > 
> > `if case 1, 2, 3 = x {` does not work because case statements can only
> > contain a single pattern when used in an if/for/while. Only when found
> > in `switch` statements can they contain multiple comma-separated
> > patterns.
> 
> But why aren’t multiple comma-separated patterns supported in
> if/for/while just like in switch statements?
> 
> I think they should be.
> 
> > 
> > `if case 1...3 = x {` works because this a single pattern `1...3`, and
> > it's equivalent to saying `if 1...3 ~= x {` (`~=` is the operator that
> > is used for doing value comparisons in patterns, and it's implemented
> > for all `IntervalType`s to call `interval.contains(x)`).
> > 
> > Also, this seems like a question that's more appropriate for swift-users
> > than swift-evolution.
> > 
> > On Thu, Dec 3, 2015, at 04:40 PM, Amir Michail wrote:
> >> But "if case 1...3 = x { ... }" works.
> >> 
> >> Why?
> >> _______________________________________________
> >> 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
> 


More information about the swift-evolution mailing list