Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more functions that tell about operators, their associativity and how they parse #23754

Merged
merged 4 commits into from
Sep 21, 2017

Conversation

dalum
Copy link
Contributor

@dalum dalum commented Sep 18, 2017

Ref: https://discourse.julialang.org/t/list-operator-associativity-in-the-documentation/5080

As far as I can tell, the rule of associativity is pretty simple and directly tied to the precedence. This, however, is not at all obvious. Hopefully this PR makes it more transparent to the user.

@JeffBezanson
Copy link
Sponsor Member

Nice. +, ++, and * are also non-associative (in the parser at least):

julia> dump(parse("a+b+c"))
Expr
  head: Symbol call
  args: Array{Any}((4,))
    1: Symbol +
    2: Symbol a
    3: Symbol b
    4: Symbol c
  typ: Any

@dalum
Copy link
Contributor Author

dalum commented Sep 19, 2017

I thought it was quite confusing that the precedence of unary operators were also not listed in the table, and found a few threads here and there suggesting that this is something people get confused about. Not sure if they read the manual, but now it's there. I also exposed the unary-op? lisp function as Base.isunaryoperator and added some docstrings for it and Base.isoperator.

I'm not sure if it makes sense to talk about associativity of unary operators, but the parser translates it into something right-associative, e. g.,

julia> :(√√√2)
:(((2)))

and not :(((√√)√)2), which would be the case for a left-associative (postfix) unary operator.

@dalum dalum changed the title Operator associativity: manual entry and new function Add more functions that tell about operators, their associativity and how they parse Sep 19, 2017
@StefanKarpinski
Copy link
Sponsor Member

Nice work on this PR!

@JeffBezanson JeffBezanson merged commit 07479c8 into JuliaLang:master Sep 21, 2017
@dalum dalum deleted the evey/assoc branch September 21, 2017 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants