JuliaLang/julia

Inconsistencies with available assignment operators

Open

#56.821 geöffnet am 13. Dez. 2024

Auf GitHub ansehen
 (16 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Julia (5.773 Forks)batch import
designduplicatefeaturehelp wanted

Repository-Metriken

Stars
 (48.709 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 23T 11h) (145 gemergte PRs in 30 T)

Beschreibung

Most of the basic "arithmetic" operators support assignment operators, where something like a += 5 is equivalent to a = a + 5. However, the presence of these seems to be somewhat inconsistent and a couple useful use-cases are missing. One use case I've ran into recently, when working with immutable structures, is wanting to update the value of a variable in-place in a similar fashion, but when applying arbitrary functions. For instance, something like

a = f(a)

or even

a = f(g(a))

The |> operator makes the latter a bit nicer to express, as

a = a |> g |> f

But it would be convenient to be able to do something like

a |>= g ∘ f

or the like instead. Furthermore, there are inconsistencies even among the more "normal" infix operators in terms of which support assignment operators; while , , and are all infix operators (giving bitwise nand, nor, and xor respectively), only ⊻= is a valid assignment operator, which feels wacky.

Contributor Guide