[swift-evolution] [swift-evolution-announce] [Review] SE-0077: Improved operator declarations

Matthew Johnson matthew at anandabits.com
Thu May 19 15:25:53 CDT 2016

> On May 19, 2016, at 3:07 PM, Антон Жилин via swift-evolution <swift-evolution at swift.org> wrote:
> Thanks Brent,
> I managed to confuse at least two people! I've stated it in the grammar, but forgot to give an example:
> ===begin===
> Multiple precedence relationships can be stated for a single precedence group. Example:
> ```swift
> precedencegroup A { }
> precedencegroup C { }
> precedencegroup B { precedence(> A) precedence(< C) }
> ```
> By transitivity, precedence of C becomes greater than precedence of A.
> ===end===
> As you can see, your suggested syntax would not look good, because there can be any number of precedence declarations.
> But I agree that bulkiness of my syntax is a problem.
> I can think of two solutions:
> 1. Global-scope precedence relationships. Example:
> precedencegroup B : associativity(left)
> precedencerelation B > A
> precedencerelation B < C
> infix operator <$> : B
> It's already included as an alternate solution.

Your argument against this in the alternatives is compelling.  We should avoid this one.

> 2. Limit precedence relationships.
> Do we really need a full-blown Directed Acyclic Graph?
> Could `above` and `between` be enough?
> Example:
> precedencegroup B : between(A, C)

Brainstorming some other options here based on Brent’s syntax

A list:
precedence NewGroup > ExistingGroup, < OtherExistingGroup left

Require braces for multiple precedence levels:
precedence NewGroup {
	> ExistingGroup
	< OtherExistingGroup

I think my preference is this “lightweight” braced option when multiple relations are necessary, with Brent’s syntax as a shorthand for the common case.

> This is one of dark places of the proposal, obviously underdiscussed.
> Are there practical situations other than `above` and `between`?
> Do we really need unlimited relationships per one precedence group?

I don’t have a concrete example, but those would not allow you to place a group above two unrelated groups.  I can’t think of a good reason for this restriction unless there are implementation considerations that make it necessary.

> - Anton
> Brent Royal-Gordon wrote:
> I like this proposal, except for the `precedencegroup` syntax, which I think is a bit overwrought. Rather than this proposal's:
> 	precedencegroup Multiplicative {
> 		associativity(left)
> 		precedence(> Additive)
> 	} 
> I would prefer to see:
> 	precedence Multiplicative > Additive left
> (Or possibly, if the `left` is deemed too inexplicable by itself, `associativity(left)`.) I don't really think the `precedence` keyword or the curly brackets bring much to the declaration, and dropping them allows us to replace the awkward compound `precedencegroup` with the shorter and equally explanatory `precedence`.
> _______________________________________________
> 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/20160519/8e8e6a45/attachment.html>

More information about the swift-evolution mailing list