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

Антон Жилин antonyzhilin at gmail.com
Thu May 19 15:07:03 CDT 2016


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.

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)

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 precedencegroup?

- 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`.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160519/d54f6bfa/attachment.html>


More information about the swift-evolution mailing list