[swift-evolution] [Pitch] Reimagining guard case/if case

Karl Wagner razielim at gmail.com
Tue Oct 25 08:36:38 CDT 2016


  
  
-1. I'm not enthusiastic about using ~=. IMO it's only a small improvement over the "if case let..." hieroglyphics and still too cryptic.
  

  
Like the others, I really like "matches" or some other, more explicit, keyword.
  

  
Anything more general around pattern-matching should probably wait until we start adding language support for regexes and other complex patterns. Then we can make something that is more logically consistent.
  

    
  
  
  

  
  
  
  

  
  
>   
> On Oct 24, 2016 at 10:55 pm,  <Haravikk via swift-evolution (mailto:swift-evolution at swift.org)>  wrote:
>   
>   
>   
>   
>   
> >   
> > On 24 Oct 2016, at 21:38, Martin Waitz via swift-evolution  <swift-evolution at swift.org (mailto:swift-evolution at swift.org)>  wrote:
> >   
> >   
> >   
> > Hi,
> >   
> >  When using a pattern match operator, I’d prefer to reverse its arguments:
> >   
> >         if value matches pattern …
> >   
> >         if result =~ .success(let x) { use(x) }
> >   
> >  Being used to pattern matching in functional languages, I also do like our current syntax.
> >  Using ~= together with `let` on the left looks very strange to me.       
>   
> That's interesting point, it does kind of make more sense that way round, but I wonder if we were to d that a keyword might be even better than an operate, like:
>   
>
>   
> if result matches .success(let x) { use(x) }
>   
> if result matches let x? { use(x) }
>   
>
>   
> And so-on? Maybe matches isn't the right keyword; we could even re-use the is keyword for something shorter (and just think of a type as a form of pattern)? I could like the idea of doing:
>   
>
>   
> if result is let x? { use(x) }
>   
>
>   
> My reasoning being that a keyword makes it much more obvious what's going on as it can read like natural language to convey that it's a form of matching, wheres ~= as an operator still requires some learning if you've not seen something similar in another language.
>  _______________________________________________ swift-evolution mailing list  swift-evolution at swift.org (mailto: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/20161025/d8b0bc1a/attachment.html>


More information about the swift-evolution mailing list