SciML / LabelledArrays.jl

Arrays which also have a label for each element for easy scientific machine learning (SciML)
https://docs.sciml.ai/LabelledArrays/stable/
Other
120 stars 21 forks source link

Make setindex! return the input array #92

Closed andreasnoack closed 3 years ago

andreasnoack commented 3 years ago

...instead of the value that is being set. This is the usual interface

julia> setindex!(ones(3), 2, 1)
3-element Vector{Float64}:
 2.0
 1.0
 1.0

The bracket syntax lowers specially to return the value instead

julia> ones(3)[1] = 2
2

julia> Meta.lower(Main, :(ones(3)[1] = 2))
:($(Expr(:thunk, CodeInfo(
    @ none within `top-level scope'
1 ─ %1 = ones(3)
│        Base.setindex!(%1, 2, 1)
└──      return 2
))))