[swift-evolution] Failable arithmetic

Brent Royal-Gordon brent at architechies.com
Fri Dec 4 19:11:07 CST 2015


> Another way to think about this as a need to modify the behavior of failing operators.  This is not intended as a syntax proposal (just to get the idea across), but wouldn’t it be cool to be able to do:
> 
>  {
>      #pragma failure_should_throw    // again, #pragma is really not the right way to spell this :-)
>      try t = m * x + c
>  }
> 
> and have the operators magically do the right thing?  Then you could generalize the behavior to support other families by using an english word to describe the semantics.  

I like the idea of having multiple semantics and selecting the one you want for an entire expression, rather than dangling sigils on all your operators.

This is, of course, easy to do if you introduce enough abstraction: <https://gist.github.com/brentdax/6fc5d717f7c85e159ec7> I assume this would be very slow as written, but perhaps the optimizer could do something along the lines of constant folding to convert the operation tree into straight-line code.

-- 
Brent Royal-Gordon
Architechies



More information about the swift-evolution mailing list