# Fill in own default for an option passed to a subfunction

**URL:** <https://discourse.julialang.org/t/fill-in-own-default-for-an-option-passed-to-a-subfunction/16114>\
**Category:** General Usage\
**Created:** [October 10, 2018, 12:44pm UTC](https://discourse.julialang.org/t/fill-in-own-default-for-an-option-passed-to-a-subfunction/16114 "2018-10-10T12:44:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)\
**Post date:** [October 10, 2018, 12:44pm UTC](https://discourse.julialang.org/t/fill-in-own-default-for-an-option-passed-to-a-subfunction/16114/1 "2018-10-10T12:44:59Z")

</div>

If I have a function `subF` that has some optional arguments, maybe (to get an MWE)

```julia
subF(a::Int; c::Int=13) = a+c

```

and in general the value `13`is a very good idea in general.

Now I write my main function (well one of them) `F` for which `13` is not a good default but let’s say `2`, still I would like to be able to pass on the options. That I can do with

```julia
function F(b::Int; kwargs...)
  # do something before and then:
  subF(2*b; kwargs...)
end

```

with this I could do `F(4)` which would call `subF(8)` such that `c` defaults to `13`. _But_ for the call from within `F`I would like that `c` defaults to `2` or in other words if `kwargs...`does not contain `c`(but maybe options for `F` or `subF`) how can I set then `c` in there to `2`?

More general: Is there a way to filter `kwargs...` within `F` such that I only pass valid options to `subF`?

---

<div class="post-metadata">

**Author:** ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)\
**Post date:** [October 11, 2018, 2:07pm UTC](https://discourse.julialang.org/t/fill-in-own-default-for-an-option-passed-to-a-subfunction/16114/2 "2018-10-11T14:07:45Z")

</div>

I found the solution myself, maybe I was thinking too complicated. To “override” the default for a sub function on can simply write F as

```julia
F(b::Int; c=2, kwargs...) = subF(2*b; c=c, kwargs...)

```

which overrides the default. It does not “filter” the remaining ones, though (as one could do in `Mathematica` for example.
