# Unpacking a named tuple using field names and slurping?

**URL:** <https://discourse.julialang.org/t/unpacking-a-named-tuple-using-field-names-and-slurping/100035>\
**Category:** General Usage\
**Created:** [June 8, 2023, 4:31am UTC](https://discourse.julialang.org/t/unpacking-a-named-tuple-using-field-names-and-slurping/100035 "2023-06-08T04:31:41Z")\
**Posts on this page:** 1\
**Showing post:** 5

<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:** [June 8, 2023, 12:57pm UTC](https://discourse.julialang.org/t/unpacking-a-named-tuple-using-field-names-and-slurping/100035/5 "2023-06-08T12:57:52Z")

</div>

You could use a macro.

```julia
julia> macro alajs(e)
           pos=findfirst(el -> startswith(string(el),string(e.args[1].args[1])), e.args[2].args)
           e.args[2].args[pos], e.args[2].args[1] = e.args[2].args[1], e.args[2].args[pos]
           return esc(e);
       end
@alajs (macro with 1 method)

julia> @alajs (y, rest...) = (x=1, y=2, z=3)
(y = 2, x = 1, z = 3)

julia> y
2

julia> rest
(x = 1, z = 3)

```

If someone explains how to expand within the macro the symbol r in the namedtuple that defines it, it would also be valid for expressions like:

`@alajs (y,rest...)=r`

---

_[View the full topic](https://discourse.julialang.org/t/unpacking-a-named-tuple-using-field-names-and-slurping/100035)._
