Julia: Feature request: allow more update operators, e.g. `a ⊗= 2` as shorthand for `a = a ⊗ 2`

Created on 20 Apr 2016  Â·  7Comments  Â·  Source: JuliaLang/julia

Only a subset of available operators allow the shorthand OPERATOR= notation. I think the current situation is that only ASCII operators are covered.
e.g.

julia> a ×= b
ERROR: syntax: unexpected "="
 in eval(::Module, ::Any) at ./boot.jl:236

I think it would be reasonable if all operators which allow binary infix syntax would also allow the shorthand. (This came up when I defined a custom ⊗ operator.)

parser

Most helpful comment

This feature would make sense because there is no situation in Julia where an operator immediately followed by an equal sign makes sense, except as an updating operator.

For example, ∪= could never make sense as anything but an updating operator. Since that is the case, it makes total sense to have the language support this feature.

All 7 comments

I think comparison operators should not be included, for consistency. After all, a >= b does not mean a = a > b.

It is always simple to define some more update operator. But the true question is whether they are _in-place_?

Not the place, @Sisyphuss.

This seems like a reasonable proposal to me – shall I mark it as accepted, @JeffBezanson?

Yes.

Not release blocking. Best!

This feature would make sense because there is no situation in Julia where an operator immediately followed by an equal sign makes sense, except as an updating operator.

For example, ∪= could never make sense as anything but an updating operator. Since that is the case, it makes total sense to have the language support this feature.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

felixrehren picture felixrehren  Â·  3Comments

StefanKarpinski picture StefanKarpinski  Â·  3Comments

sbromberger picture sbromberger  Â·  3Comments

m-j-w picture m-j-w  Â·  3Comments

wilburtownsend picture wilburtownsend  Â·  3Comments