Julia: Parse suffixed operators with chains

Created on 16 Jul 2018  ·  2Comments  ·  Source: JuliaLang/julia

Currently, suffixed operators (#22089) are all parsed as binary function calls. However, it seems natural that operators which are normally parsed as chains should have their suffixed versions inherit this behavior.

julia> :(a + b + c)
:(a + b + c)

julia> :(a +ₐ b +ₐ c)
:((a +ₐ b) +ₐ c)

julia> :(+(a, b, c))
:(a + b + c)

julia> :(+ₐ(a, b, c))
:(+ₐ(a, b, c))
parser speculative

Most helpful comment

One problem with doing this is that it would make operators like +ₐ harder to override, since in the common case where you only want to define the two-argument version you'd have to also implement a fallback like https://github.com/JuliaLang/julia/blob/b012ab3a44b64a145d993824319abe00d77e8e32/base/operators.jl#L497-L507

All 2 comments

At first glance, it looks like all that would need to be done would be to change (memq t chain-ops) to (memq (maybe-strip-op-suffix t) chain-ops) in julia-parser.scm (two lines).

One problem with doing this is that it would make operators like +ₐ harder to override, since in the common case where you only want to define the two-argument version you'd have to also implement a fallback like https://github.com/JuliaLang/julia/blob/b012ab3a44b64a145d993824319abe00d77e8e32/base/operators.jl#L497-L507

Was this page helpful?
0 / 5 - 0 ratings

Related issues

TotalVerb picture TotalVerb  ·  3Comments

iamed2 picture iamed2  ·  3Comments

felixrehren picture felixrehren  ·  3Comments

manor picture manor  ·  3Comments

omus picture omus  ·  3Comments