[swift-evolution] [Discussion] Breaking precedence

John McCall rjmccall at apple.com
Mon Aug 1 17:06:10 CDT 2016

> On Aug 1, 2016, at 3:01 PM, Anton Zhilin via swift-evolution <swift-evolution at swift.org> wrote:
> 2016-08-02 0:52 GMT+03:00 Xiaodi Wu <xiaodi.wu at gmail.com <mailto:xiaodi.wu at gmail.com>>:
> On Mon, Aug 1, 2016 at 4:41 PM, Anton Zhilin via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> Disclaimer: I have not (yet) prepared a proposal, or even something that could be considered a draft, but I want to hear public opinion on the topic.
> SE-0077 (about precedence groups) has been successfully implemented for Swift 3. (A thousand thanks to John McCall!) It suggests a model where we can prohibit certain operators from standing next to each other.
> This was intended to be the second part of that proposal. We now have to think if we should drop some precedence relationships between standard operators. Here are examples of parentheses dropping that can be ambiguous to reader:
> 1/3 as Double   // should we prohibit this?
> Why should we? I would absolutely want that to work exactly as it does now (0.333333...).
> Strange enough, I've just run it and yes, 0.333333... But casting precedence is lower than multiplicative, so I thought it would parse as '(1/3) as Double'. Is it a bug?

You're applying C-style thinking.  Swift does not have implicit promotions.  Coercing the result of 1/3 to Double forces the operands to be Doubles as well.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160801/3fa71f88/attachment.html>

More information about the swift-evolution mailing list