# Destructuring of NamedTuple in julia 1.10

**URL:** <https://discourse.julialang.org/t/destructuring-of-namedtuple-in-julia-1-10/129308>\
**Category:** General Usage\
**Tags:** syntax, namedtuple, destructuring, splat\
**Created:** [May 25, 2025, 3:39am UTC](https://discourse.julialang.org/t/destructuring-of-namedtuple-in-julia-1-10/129308 "2025-05-25T03:39:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![o314](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/o314/32/252_2.png) [@o314](https://discourse.julialang.org/u/o314)\
**Post date:** [May 25, 2025, 3:39am UTC](https://discourse.julialang.org/t/destructuring-of-namedtuple-in-julia-1-10/129308/1 "2025-05-25T03:39:24Z")

</div>

I wonder if there is a way to destructure a namedtuple with splatting like this

```julia
(; a, nt...) = (; a=1, b=2, c=3)

```

where one is expecting to get `a = 1` and `nt = (; b=2, c=3)` setted  
This forms fails @ home with julia v1.10 and history.md does not mention any change

Currently those forms work to compute the result

```julia
Base.structdiff((; a=1, b=2, c=3), NamedTuple{(:a,)})
Base.structdiff((; a=1, b=2, c=3), (; a=nothing))

```

but curiously not this one

```julia
Base.structdiff((; a=1, b=2, c=3), (:a,))

```

SEE ALSO

- [https://discourse.julialang.org/t/destructuring-syntax-in-julia-1-7/](https://discourse.julialang.org/t/destructuring-syntax-in-julia-1-7/)

---

<div class="post-metadata">

**Author:** ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Post date:** [May 25, 2025, 6:26am UTC](https://discourse.julialang.org/t/destructuring-of-namedtuple-in-julia-1-10/129308/2 "2025-05-25T06:26:36Z")

</div>

try this way

```julia
 a, nt... = (; a=1, b=2, c=3)

```

---

<div class="post-metadata">

**Author:** ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Post date:** [May 25, 2025, 6:37am UTC](https://discourse.julialang.org/t/destructuring-of-namedtuple-in-julia-1-10/129308/3 "2025-05-25T06:37:25Z")

</div>

I wonder why in the third case we get a result similar to the first and not the second

```julia
julia> f, nt... = (; a=1, b=2, c=3)
(a = 1, b = 2, c = 3)

julia> f
1

julia> nt
(b = 2, c = 3)

julia> f, nt... = [(; a=1, b=2, c=3)...,]
3-element Vector{Int64}:
 1
 2
 3

julia> f
1

julia> 

julia> nt
2-element Vector{Int64}:
 2
 3

julia> f, nt... = ((; a=1, b=2, c=3)...,)
(1, 2, 3)

julia> f
1

julia> nt
(b = 2, c = 3)

```

---

<div class="post-metadata">

**Author:** ![o314](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/o314/32/252_2.png) [@o314](https://discourse.julialang.org/u/o314)\
**Post date:** [May 25, 2025, 2:35pm UTC](https://discourse.julialang.org/t/destructuring-of-namedtuple-in-julia-1-10/129308/4 "2025-05-25T14:35:13Z")

</div>

OK for `a, nt... = (; a=1, b=2, c=3)`

In the frontend everything is driven by tuple when you destructure. so that catches too an inner namedtuple

After the lowering, everything tends to be array/vector-oriented.  
When you splat out inside a container, it will iterate / collect silently  
The two cases you point out is the default case there since a namedtuple iterates on value

`@assert (; a=1, b=2, c=3) |> collect == [1, 2, 3]`

So we’ve got a solution, but it’s a bit tricky and inconsistent. Half of a bug

The parser/lowerer may handle this case better. But what about

`f, nt... = identity(((; a=1, b=2, c=3)...,))` or  
`f, nt... = ((; a=1, b=2, c=3)...,) |> identity`  
`f, nt... = ((; a=1, b=2, c=3)...,) |> myident`

There must be a frontier. Moreover The scheme & julia code there is very hard to maintain / onboard / evolve.  
_It’s well known Scheme is a famous prankster when it’s about lisping on S_

SEE

- [julia/src/julia-syntax.scm at master · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/blob/master/src/julia-syntax.scm)

- [JuliaLowering.jl/src/desugaring.jl at main · c42f/JuliaLowering.jl · GitHub](https://github.com/c42f/JuliaLowering.jl/blob/main/src/desugaring.jl)
