JuliaData / NamedTuples.jl

[DEPRECATED] NamedTuples.jl
Other
30 stars 17 forks source link

setindex doesn't seem to work as advertised #40

Open tcovert opened 7 years ago

tcovert commented 7 years ago
julia> using NamedTuples

julia> NamedTuples.setindex(@NT(a=1, b=2), :b, "cde")
(a = 1, b = 2)

I would have thought the result would be (a = 1, b = "cde")

nalimilan commented 6 years ago

Confirmed. The docstring says: "Create a new NamedTuple with the new value set on it, either overwriting the old value or appending a new value." But the implementation uses merge which (as documented) takes the LHS. It would make sense to use the RHS instead since that's how merge works in general, and how NamedTuple is going to be implemented in Base. Also setindex isn't very useful if it doesn't overwrite existing values.