# Sharing keyword args between functions

**URL:** https://discourse.julialang.org/t/sharing-keyword-args-between-functions/4978
**Category:** General Usage
**Tags:** question
**Created:** [July 20, 2017, 1:56pm UTC](https://discourse.julialang.org/t/sharing-keyword-args-between-functions/4978 "2017-07-20T13:56:16Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [July 20, 2017, 1:56pm UTC](https://discourse.julialang.org/t/sharing-keyword-args-between-functions/4978/1 "2017-07-20T13:56:16Z")

</div>

_This is a style question, I already have a solution, just looking for opinions._

Sometimes I find it convenient to specify defaults with keyword arguments for a couple of functions, which are then invoked by some other function, where I don’t want to repeat the defaults. So I collect the keywords args with `...`, and pass them on. But I need to collect the unused ones in the functions that are called; anticipating [#9343](https://github.com/JuliaLang/julia/issues/9343) I am doing it like this (MWE):

```julia
pick_a(; a = 5, _...) = a
pick_b(; b = 7, _...) = b
ab(; args...) = pick_a(; args...) + pick_b(; args...)
ab() # 12
ab(; a = 1) # 8

```

Is this an OK interface design? Are there any caveats?

(_I know that for anything more serious I should wrap parameters up in a `struct`, but that is sometimes too involved_).

---

<div class="post-metadata">

### Author: ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)
#### Post date: [July 20, 2017, 2:24pm UTC](https://discourse.julialang.org/t/sharing-keyword-args-between-functions/4978/2 "2017-07-20T14:24:50Z")

</div>

Looks fine as long as it doesn’t get too messy. (Doesn’t sound too useful for simple `pick_*` but could be useful when there are multiple parts that each do something with part of the kws).

Do note that this currently come with a high performance cost. Once the performance cost is fixed though, this will likely be no different from `wrap parameters up in a struct`.

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [July 20, 2017, 2:38pm UTC](https://discourse.julialang.org/t/sharing-keyword-args-between-functions/4978/3 "2017-07-20T14:38:18Z")

</div>

> [@yuyichao](#):
>
> high performance cost

I am using this for high-level logic so it should not matter, but I am curious about it; can you tell me which issues/PRs I should read up on and follow?

---

<div class="post-metadata">

### Author: ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)
#### Post date: [July 20, 2017, 2:49pm UTC](https://discourse.julialang.org/t/sharing-keyword-args-between-functions/4978/4 "2017-07-20T14:49:18Z")

</div>

[https://github.com/JuliaLang/julia/pull/22194](https://github.com/JuliaLang/julia/pull/22194)  
[https://github.com/JuliaLang/julia/pull/21915](https://github.com/JuliaLang/julia/pull/21915)  
[https://github.com/JuliaLang/julia/pull/16580](https://github.com/JuliaLang/julia/pull/16580)
