[swift-evolution] Proposal: Pattern Matching Partial Function (#111)
Craig Cruden
ccruden at novafore.com
Fri Jan 29 03:28:07 CST 2016
So the solution to everything in the proposal is to create a mutable variable and then a bunch of if statements in inverse format?
Then take that and embed in a “pure” function where you need closures?
And forget about pattern matching and decomposing enums?
And this is the solution to “all”?
> On 2016-01-29, at 16:09:19, James Campbell via swift-evolution <swift-evolution at swift.org> wrote:
>
> I think all of this could be solved by just having postfix if statements
>
> var str: String?
>
> str = "hot" if state == .Hot
> str = "cold" if state == .Cold
>
> //if the ??= operator proposal is accepted then we could just do:
> str ??= "Invalid Temperature"
>
>
> This is used a lot in Ruby, more flexible since it could be used on any line of code, flexible and concise. I think it reads quite well so beginners will grasp it easily (as I did when writing my first Ruby)
>
> I think compiler wise it could be treated like a do while loop except it only loops once ;)
>
> Sent from my iPhone
>
> On 29 Jan 2016, at 08:06, Charles Constant via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>
>> Sorry for the barrage here, Paul :)
>>
>> > I’m not even convinced the new syntax is clearer so much as cleverer.
>>
>> As I've followed the various threads for switch-like assignments, I've been thinking a lot about how valid it is to say that more explicit is all that helpful to beginners. I wish I had the resources to test these assumptions with actual people who had never written Swift.
>>
>> As an example.
>>
>> We assume that this:
>>
>> let phrase: String
>> switch( temperature ) {
>> case .Cold: str = "Too cold"
>> case .Hot: str = "Too hot"
>> default: str = "Just right"
>> }
>>
>> is going to be easier for beginners than something like this:
>>
>> let phrase = temperature ?
>> "Too cold" if .Cold :
>> "Too hot” if .Hot :
>> "Just right" if _
>>
>> I'm using a short version here that is not the actual proposal, and that we won't use (since we don't want to overload "if"). But I have a strong hunch that a beginner is not going to find the longer version any more clear. There's a lot of syntax for the programmer to parse in the "switch" statement, as it stands. I suspect the less redundancy we have, the easier it is to figure out what is going on.
>>
>>
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution <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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160129/02b4a1e3/attachment.html>
More information about the swift-evolution
mailing list