Skip to content
This repository has been archived by the owner on Jun 4, 2019. It is now read-only.

Can't construct tuple with "implicit" fieldname unless all are. #70

Open
goretkin opened this issue May 16, 2018 · 3 comments
Open

Can't construct tuple with "implicit" fieldname unless all are. #70

goretkin opened this issue May 16, 2018 · 3 comments

Comments

@goretkin
Copy link

julia> (a,b) = (1, 2.3) 
(1, 2.3)

julia> @NT(a,b)
NamedTuples._NT_a_b

julia> @NT(a,b=2.4)
ERROR: Invalid tuple, all values must be specified during construction @ (b = 2.4)

julia> Pkg.status("NamedTuples")
 - NamedTuples                   4.0.2
@omus
Copy link
Member

omus commented May 31, 2018

Note that @NT(a,b) is returning a type not a named tuple with the values of a and b:

julia> typeof(@NT(a,b))
UnionAll

julia> typeof(@NT(1,2.3))
NamedTuples._NT___1_____2__{Int64,Float64}

Note you can get an instance using the names a and b via:

julia> @NT(a=a,b=b)
(a = 1, b = 2.3)

@goretkin
Copy link
Author

goretkin commented May 31, 2018

Thanks for pointing that out. I hadn't noticed that. I ran into this "issue" this morning and I thought I was doing something wrong, but it turns out I had just assumed this feature exists.

So I guess this issue isn't a bug, but a feature request. I'm not sure it's a good feature, but it would come in handy for many of my uses of named tuples.

@omus
Copy link
Member

omus commented May 31, 2018

If this feature were to be added we would probably need to separate the creation of named tuple types and instances to avoid additional confusion.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants