# What does tuple splatting do?

**URL:** <https://discourse.julialang.org/t/what-does-tuple-splatting-do/13307>\
**Category:** Internals & Design\
**Created:** [August 12, 2018, 4:30pm UTC](https://discourse.julialang.org/t/what-does-tuple-splatting-do/13307 "2018-08-12T16:30:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)\
**Post date:** [August 12, 2018, 4:30pm UTC](https://discourse.julialang.org/t/what-does-tuple-splatting-do/13307/1 "2018-08-12T16:30:36Z")

</div>

If `t` is a tuple of 2 elements of type `A` and `B`, what does

```julia
a, b = t

```

do ? Is it equivalent to

```julia
a = t[1]
b = t[2]

```

or does it do something else ?  
While updating [Polyhedra](https://github.com/JuliaPolyhedra/Polyhedra.jl/) to Julia v0.7, I hit a [weird issue](https://github.com/JuliaPolyhedra/Polyhedra.jl/issues/109) where `a` and `b` have types `Vector` instead of `A` and `B` as expected. Moreover, when asking for the length of `b` I get a number that seems to large to have a vector of this size fitting in memory.

---

<div class="post-metadata">

**Author:** ![dawbarton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dawbarton/32/215461_2.png) [@dawbarton](https://discourse.julialang.org/u/dawbarton)\
**Post date:** [August 12, 2018, 5:12pm UTC](https://discourse.julialang.org/t/what-does-tuple-splatting-do/13307/2 "2018-08-12T17:12:17Z")

</div>

You can see what it does by using `@code_lowered`, for example

```julia
f(t) = begin a, b = t; end
@code_lowered f([:a, Float64])

```

gives

```julia
CodeInfo(
1 1 ─ %1 = (Base.indexed_iterate)(t, 1) │
  │ a = (Core.getfield)(%1, 1) │
  │ #temp# = (Core.getfield)(%1, 2) │
  │ %4 = (Base.indexed_iterate)(t, 2, #temp#) │
  │ b = (Core.getfield)(%4, 1) │
  │ #temp# = (Core.getfield)(%4, 2) │
  └── return t │
)

```

So it’s iterating over `t` (the `indexed_iterate` call) and putting the result in the `a` and then `b` variables.

(I think the `indexed_iterate` function returns a tuple of the value and the iterator state and the subsequent `getfield` is just getting the first element of that tuple, the value.)
