# Metaprogramming: Splatting of key word arguments

**URL:** <https://discourse.julialang.org/t/metaprogramming-splatting-of-key-word-arguments/61092>\
**Category:** New to Julia\
**Created:** [May 13, 2021, 3:28pm UTC](https://discourse.julialang.org/t/metaprogramming-splatting-of-key-word-arguments/61092 "2021-05-13T15:28:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jt1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jt1/32/38331_2.png) [@jt1](https://discourse.julialang.org/u/jt1)\
**Post date:** [May 13, 2021, 3:28pm UTC](https://discourse.julialang.org/t/metaprogramming-splatting-of-key-word-arguments/61092/1 "2021-05-13T15:28:51Z")

</div>

In [the docs](https://docs.julialang.org/en/v1/manual/metaprogramming/#Splatting-interpolation) there is this example of metaprogramming:

```julia
julia> args = [:x, :y, :z];

julia> :(f(1, $(args...)))
:(f(1, x, y, z))

```

Now i would like to do the same for keyword arguments:

```julia
julia> kwargs = [:(x=nothing), :(y=nothing), :(z=nothing)];

julia> :(f(1; $(kwargs...)))
:(f(1; $(Expr(:(=), :x, :nothing)), $(Expr(:(=), :y, :nothing)), $(Expr(:(=), :z, :nothing))))

```

Which is not what I expected.  
Is there any way to do this? I tried splatting a `Dict` instead. But it also didn’t work.

---

<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:** [May 13, 2021, 3:56pm UTC](https://discourse.julialang.org/t/metaprogramming-splatting-of-key-word-arguments/61092/2 "2021-05-13T15:56:33Z")

</div>

Keyword arguments are written with `=`, but they actually get parsed as a special kind of expression whose head is `:kw` not `:=`. You can see this with `dump`:

```julia
julia> dump(:(f(;x = 1)))
Expr
  head: Symbol call
  args: Array{Any}((2,))
    1: Symbol f
    2: Expr
      head: Symbol parameters
      args: Array{Any}((1,))
        1: Expr
          head: Symbol kw
          args: Array{Any}((2,))
            1: Symbol x
            2: Int64 1

```

So I can make your example work by doing:

```julia
julia> kwargs = [Expr(:kw, :x, :nothing), Expr(:kw, :y, :nothing), Expr(:kw, :z, :nothing)];

julia> :(f(1; $(kwargs...)))
:(f(1; x = nothing, y = nothing, z = nothing))

```
