NamedTuples.jl
NamedTuples.jl copied to clipboard
Infer name
It would be great if the following syntax
a = 3
b = "something"
x = @NT(a,b)
would be equivalent to
x = @NT(a=>a,b=>b)
Ideally this would also work with immutables in the following way:
a = @NT(somename => 34)
x = @NT(a.somename)
and then x
would have one member with name somename
. In cases where no name can be inferred it could assign automatic names:
x = @NT(x^2)
would assign an automatic name to its one member.
This syntax would obviously break the current syntax for defining NamedTuples... But maybe that could just get its own macro, e.g. @DNT
or something like that?
I kind of like that, so take the variable names from the macro and 'close' in the current values to the named tuple?
Yep, essentially just the way C# handles this for their anonymous types.
If you are ok with this, I can prep a PR. I have implemented something like this already in Query.jl, so it would just be a matter of taking my code from there and moving it into the package here, I believe.
Makes sense to me.
I was just looking for this as well.