# Function keyword argument packing and unpacking

**URL:** <https://discourse.julialang.org/t/function-keyword-argument-packing-and-unpacking/23053>\
**Category:** General Usage\
**Created:** [April 11, 2019, 8:34pm UTC](https://discourse.julialang.org/t/function-keyword-argument-packing-and-unpacking/23053 "2019-04-11T20:34:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bomber8013](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bomber8013/32/7927_2.png) [@bomber8013](https://discourse.julialang.org/u/bomber8013)\
**Post date:** [April 11, 2019, 8:34pm UTC](https://discourse.julialang.org/t/function-keyword-argument-packing-and-unpacking/23053/1 "2019-04-11T20:34:13Z")

</div>

Current behavior is this:

```julia
julia> f(;kwargs...) = kwargs
f (generic function with 1 method)

julia> f(a=1, b=2)
pairs(::NamedTuple) with 2 entries:
  :a => 1
  :b => 2

julia> f(f(a=1, b=2)...)
ERROR: MethodError: no method matching f(::Pair{Symbol,Int64}, ::Pair{Symbol,Int64})
Stacktrace:
 [1] top-level scope at none:0

```

Shouldn’t this be true?

```julia
f(f(a=1, b=2)...) == f(a=1, b=2)

```

This would allow things such as calls to a function is more dynamic ways than just passing an unpacked tuple or vector. Such as below:

```julia
julia> d = Dict(:a => 1, :b => 2)
Dict{Symbol,Int64} with 2 entries:
  :a => 1
  :b => 2

Dict(f(d...)) == d

```

I apologize ahead of time for lack of good writing style. I have done about 3 forum posts in my life.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [April 11, 2019, 9:11pm UTC](https://discourse.julialang.org/t/function-keyword-argument-packing-and-unpacking/23053/2 "2019-04-11T21:11:47Z")

</div>

You’re very close, but you need to explicitly pass the pairs as keyword arguments, like so:

```julia
julia> f(;f(a = 1, b=2)...)
pairs(::NamedTuple) with 2 entries:
  :a => 1
  :b => 2

```

Otherwise your arguments are interpreted as a sequence of _positional_ (not keyword) arguments.

---

<div class="post-metadata">

**Author:** ![bomber8013](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bomber8013/32/7927_2.png) [@bomber8013](https://discourse.julialang.org/u/bomber8013)\
**Post date:** [April 11, 2019, 9:13pm UTC](https://discourse.julialang.org/t/function-keyword-argument-packing-and-unpacking/23053/3 "2019-04-11T21:13:53Z")

</div>

Doh! why didn’t I think of that before I posted this? Thank you very much! I guess that classifies this post as a “usage” post…
