# \#destructuring

**URL:** https://discourse.julialang.org/tag/destructuring/1161.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Reflections on an typo (getindex(::NamedTuple, ...))](https://discourse.julialang.org/t/reflections-on-an-typo-getindex-namedtuple/133331)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 4\
**Last updated:** [October 22, 2025, 8:38am UTC](https://discourse.julialang.org/t/reflections-on-an-typo-getindex-namedtuple/133331 "2025-10-22T08:38:57Z")

</div>

I have recently finished debugging some code, with an error deep inside a calculation that wasted me a few hours. I wish to emphasize that this is not a bug in Julia. It is my error. But, as you will see below, I can en…

---

## [Destructuring of NamedTuple in julia 1.10](https://discourse.julialang.org/t/destructuring-of-namedtuple-in-julia-1-10/129308)

<div class="topic-metadata">

**Author:** [@o314](https://discourse.julialang.org/u/o314)\
**Replies:** 3\
**Last updated:** [May 25, 2025, 2:35pm UTC](https://discourse.julialang.org/t/destructuring-of-namedtuple-in-julia-1-10/129308 "2025-05-25T14:35:13Z")

</div>

I wonder if there is a way to destructure a namedtuple with splatting like this (; 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.1…

---

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

<div class="topic-metadata">

**Author:** [@xfcjscn](https://discourse.julialang.org/u/xfcjscn)\
**Replies:** 66\
**Last updated:** [October 27, 2022, 7:21am UTC](https://discourse.julialang.org/t/destructuring-syntax-in-julia-1-7/68236 "2022-10-27T07:21:46Z")

</div>

1.7 introduced new language feature: (; a, b) = x can now be used to destructure properties a and b of x . This syntax is equivalent to a = getproperty(x, :a); b = getproperty(x, :b) From a reader perspective(much more…

---

## [Slurping in not final position](https://discourse.julialang.org/t/slurping-in-not-final-position/102784)

<div class="topic-metadata">

**Author:** [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Replies:** 11\
**Last updated:** [August 15, 2023, 12:45pm UTC](https://discourse.julialang.org/t/slurping-in-not-final-position/102784 "2023-08-15T12:45:10Z")

</div>

I was running the roames notebook exercises, in an attempt to fix this: Create a more generic reduce2 function that works recursively over a tuple For the operations + and \*, being associative, simulate the operatio…

---

## [Property destructuring](https://discourse.julialang.org/t/property-destructuring/101550)

<div class="topic-metadata">

**Author:** [@Ralf\_Dietrich](https://discourse.julialang.org/u/Ralf_Dietrich)\
**Replies:** 5\
**Last updated:** [July 12, 2023, 9:46pm UTC](https://discourse.julialang.org/t/property-destructuring/101550 "2023-07-12T21:46:06Z")

</div>

Unter Property destructoring I found a simple example for property destructuring. (; b, a) = (a=1, b=2, c=3) I understand how it works, but it is not clear to me where you can use this practically. Can someone show m…

---

## [Decomposing struct in function argument](https://discourse.julialang.org/t/decomposing-struct-in-function-argument/97468)

<div class="topic-metadata">

**Author:** [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Replies:** 4\
**Last updated:** [May 8, 2023, 12:06am UTC](https://discourse.julialang.org/t/decomposing-struct-in-function-argument/97468 "2023-05-08T00:06:08Z")

</div>

is it possible to to something like this? struct X a b end f((a,b)::X) = a+b

---

## [Assigning struct to multiple variables](https://discourse.julialang.org/t/assigning-struct-to-multiple-variables/88763)

<div class="topic-metadata">

**Author:** [@HMegh](https://discourse.julialang.org/u/HMegh)\
**Replies:** 6\
**Last updated:** [October 15, 2022, 12:33pm UTC](https://discourse.julialang.org/t/assigning-struct-to-multiple-variables/88763 "2022-10-15T12:33:20Z")

</div>

I would like to export a struct to variables. Say I have the following struct struct point x::Float64 y::Float64 end and I use it to define a point A=point(3.0,4.0) Is there a concise way to extract the…

---

## [Destructuring syntax does not respect const annotation](https://discourse.julialang.org/t/destructuring-syntax-does-not-respect-const-annotation/88751)

<div class="topic-metadata">

**Author:** [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Replies:** 2\
**Last updated:** [October 14, 2022, 8:55pm UTC](https://discourse.julialang.org/t/destructuring-syntax-does-not-respect-const-annotation/88751 "2022-10-14T20:55:32Z")

</div>

The const keyword seems to have no effect when used with the destructuring syntax in Julia 1.7+. julia\> t = (;a = 1, b = 2); julia\> const (;a, b) = t (a = 1, b = 2) julia\> a = 3 # re-definition produces no error or wa…

---

## [Destructuring NamedTuples with Regular Expressions](https://discourse.julialang.org/t/destructuring-namedtuples-with-regular-expressions/88509)

<div class="topic-metadata">

**Author:** [@alfaromartino](https://discourse.julialang.org/u/alfaromartino)\
**Replies:** 6\
**Last updated:** [October 10, 2022, 8:41pm UTC](https://discourse.julialang.org/t/destructuring-namedtuples-with-regular-expressions/88509 "2022-10-10T20:41:28Z")

</div>

As of Julia 1.7, one can deconstruct NamedTuples. I wanted to know if it’s possible to use regular expressions to do this, rather than specifying the variables to be deconstructured. MWE: x = (; a11=1, a12=2, b1=3) #t…

---

## [Namedtuple destructuring in macro fails roughly due to macro hygiene (since gensym goes eagerly)](https://discourse.julialang.org/t/namedtuple-destructuring-in-macro-fails-roughly-due-to-macro-hygiene-since-gensym-goes-eagerly/86172)

<div class="topic-metadata">

**Author:** [@o314](https://discourse.julialang.org/u/o314)\
**Replies:** 2\
**Last updated:** [September 8, 2022, 9:14am UTC](https://discourse.julialang.org/t/namedtuple-destructuring-in-macro-fails-roughly-due-to-macro-hygiene-since-gensym-goes-eagerly/86172 "2022-09-08T09:14:35Z")

</div>

Here is the situation f(x) = (; a=2x, b=x\*x) macro ma(x) quote f($x) end end macro mb(x) quote nt = f($x) (; nt.a, nt.b) end end macro mc(x) quote (; a,b) = f($x) …

---

## [How to desctructure a namedtuple and declare the variables to be constants using the new destructuring syntax?](https://discourse.julialang.org/t/how-to-desctructure-a-namedtuple-and-declare-the-variables-to-be-constants-using-the-new-destructuring-syntax/76830)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 1\
**Last updated:** [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 "2022-02-21T06:15:12Z")

</div>

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\> (; a) = nt (a = 1,) Is there any way to use this syntax a…
