NamedTuples.jl icon indicating copy to clipboard operation
NamedTuples.jl copied to clipboard

Infer name

Open davidanthoff opened this issue 8 years ago • 4 comments

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?

davidanthoff avatar Aug 21 '16 17:08 davidanthoff

I kind of like that, so take the variable names from the macro and 'close' in the current values to the named tuple?

mdcfrancis avatar Sep 15 '16 17:09 mdcfrancis

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.

davidanthoff avatar Sep 15 '16 18:09 davidanthoff

Makes sense to me.

mdcfrancis avatar Sep 15 '16 23:09 mdcfrancis

I was just looking for this as well.

axsk avatar Jul 03 '18 13:07 axsk