<div dir="ltr">I mostly agree with everything you said. I also think &quot;if case&quot; syntax is bad at the moment.<br><div><font face="monospace, monospace"><br></font></div>However I think any changes probably have to be an addition rather than a replacement.<div><br></div><div>I&#39;ve tried to reconcile these changes with pattern matching and cannot work out how it fits. There&#39;s too many inconsistencies and incompatibilities. At best you can make a new pattern matching syntax that&#39;s incompatible with switch statements.<div><div><div><br>On Tuesday, 2 February 2016, Brent Royal-Gordon via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">&gt;   if bind foo {<br>
&gt;       // foo is non-optional in here<br>
&gt;   }<br>
<br>
If something in a flow control statement should read like an assertion, we don&#39;t want &quot;bind&quot; here.<br>
<br>
        if has foo {<br>
                // foo is non-optional<br>
        }<br>
<br>
However, I do note that pattern matching in an if statement already lets you do the same thing as `if let` more explicitly:<br>
<br>
        if case let foo? = bar {<br>
<br>
        }<br>
<br>
I wonder if we should instead enhance this feature&#39;s usability. For instance, as a surgical change, we could drop the `case` keyword when `let` is present in the condition (since `let` isn&#39;t allowed in a boolean expression anyway):<br>
<br>
        if let foo? = bar {<br>
<br>
        }<br>
<br>
This is one character longer than the current `if let`, but it falls naturally out of other language features and allows for other similar constructs, like `if let .Success(value) = bar`.<br>
<br>
However, the `if case` syntax kind of sucks in other ways, too, and I think it deserves another look. In particular, the `=` isn&#39;t great for pattern matching that doesn&#39;t bind variables; people have complained about that part of `if case` before. Maybe we can improve that while still making the unwrapping good by introducing a keyword or operator that replaces the `=` while implying the `case` so it doesn&#39;t have to be stated explicitly. Here&#39;s a strawman of what this would look like, using `matches`:<br>
<br>
        if let foo? matches bar<br>
        if let .Success(value) matches bar<br>
        if .Card(let rank, .Heart) matches bar<br>
        if .OK matches bar<br>
<br>
Can we do this with `for case` too? Maybe...<br>
<br>
        for let foo? matches in bars<br>
        for let .Success(value) matches in bars<br>
        for .Card(let rank, .Heart) matches in bars<br>
        for .OK matches in bars<br>
<br>
I think this approach might work; the only question is what `matches` should be. I don&#39;t like using a keyword for it; I think it disappears too easily, particularly in the optional case. We do sort of have a pattern matching operator, `~=`, but it&#39;s very obscure, the overloading is not really right, and I can never remember which order the characters go in (possibly because Perl uses `=~` as its matching operator). Colon kind of reads well, but it disappears too easily, and it&#39;s already associated with typing:<br>
<br>
        if let foo?: bar<br>
        if let .Success(value): bar<br>
        if .Card(let rank, .Heart): bar<br>
        if .OK: bar<br>
<br>
I don&#39;t know what the answer is here, but I think this might be a good line to pursue.<br>
<br>
--<br>
Brent Royal-Gordon<br>
Architechies<br>
<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a>swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div></div>
</div></div></div>