<div dir="ltr">I mostly agree with everything you said. I also think "if case" 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've tried to reconcile these changes with pattern matching and cannot work out how it fits. There's too many inconsistencies and incompatibilities. At best you can make a new pattern matching syntax that's incompatible with switch statements.<div><div><div><br>On Tuesday, 2 February 2016, Brent Royal-Gordon via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> 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">> if bind foo {<br>
> // foo is non-optional in here<br>
> }<br>
<br>
If something in a flow control statement should read like an assertion, we don't want "bind" 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's usability. For instance, as a surgical change, we could drop the `case` keyword when `let` is present in the condition (since `let` isn'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't great for pattern matching that doesn'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't have to be stated explicitly. Here'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'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'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'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'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>