# How to desctructure a namedtuple and declare the variables to be constants using the new destructuring syntax?

**URL:** <https://discourse.julialang.org/t/how-to-desctructure-a-namedtuple-and-declare-the-variables-to-be-constants-using-the-new-destructuring-syntax/76830>\
**Category:** General Usage\
**Tags:** question, constants, destructuring\
**Created:** [February 21, 2022, 5:13am UTC](https://discourse.julialang.org/t/how-to-desctructure-a-namedtuple-and-declare-the-variables-to-be-constants-using-the-new-destructuring-syntax/76830 "2022-02-21T05:13:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [February 21, 2022, 5:13am UTC](https://discourse.julialang.org/t/how-to-desctructure-a-namedtuple-and-declare-the-variables-to-be-constants-using-the-new-destructuring-syntax/76830/1 "2022-02-21T05:13:11Z")

</div>

```julia
julia> const nt = (; a = 1)
(a = 1,)

julia> const a_ = nt.a
1

```

This defines `a_` as a constant. Now julia v1.7 has introduced the new destructuring syntax

```julia
julia> (; a) = nt
(a = 1,)

```

Is there any way to use this syntax and declare `a` to be a constant as well? Something like this doesn’t work:

```julia
julia> (; const a) = nt
ERROR: syntax: expected assignment after "const"

```

---

<div class="post-metadata">

**Author:** ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)\
**Post date:** [February 21, 2022, 6:15am UTC](https://discourse.julialang.org/t/how-to-desctructure-a-namedtuple-and-declare-the-variables-to-be-constants-using-the-new-destructuring-syntax/76830/2 "2022-02-21T06:15:12Z")

</div>

This seems to work:

```julia
julia> nt = (; a = "hi")
(a = "hi",)

julia> (const a; (; a) = nt)
(a = "hi",)

julia> a = "bye"
WARNING: redefinition of constant a. This may fail, cause incorrect answers, or produce other errors.
"bye"

```

Kind of strange though.

edit:

```julia
julia> begin
           const a
           (; a) = nt
       end
(a = "hi",)

```

works too, and might be a bit more clear.
