# How keyword arguments kwfuncs work

**URL:** <https://discourse.julialang.org/t/how-keyword-arguments-kwfuncs-work/46840>\
**Category:** Internals & Design\
**Created:** [September 18, 2020, 1:01pm UTC](https://discourse.julialang.org/t/how-keyword-arguments-kwfuncs-work/46840 "2020-09-18T13:01:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)\
**Post date:** [September 18, 2020, 1:01pm UTC](https://discourse.julialang.org/t/how-keyword-arguments-kwfuncs-work/46840/1 "2020-09-18T13:01:10Z")

</div>

A collegue who was contributing to the internals of Zygote wanted to understand what was going on with

[https://github.com/FluxML/Zygote.jl/blob/ed366f32c0f520567526040d9f8acaf0d83613c3/src/compiler/chainrules.jl#L33](https://github.com/FluxML/Zygote.jl/blob/ed366f32c0f520567526040d9f8acaf0d83613c3/src/compiler/chainrules.jl#L33)  
and  
[https://github.com/FluxML/ZygoteRules.jl/blob/699dbc293dc27f21e82460d87b7e58dd3f388984/src/adjoint.jl#L52](https://github.com/FluxML/ZygoteRules.jl/blob/699dbc293dc27f21e82460d87b7e58dd3f388984/src/adjoint.jl#L52)

I gave a bit of an explination of `f(x, kwargs...)` lowering to `f(::Core.kwfunc(typeof(f)), kwargs, x)`  
and the kwfunc function handling sorting the order of the keywords and filling in missing ones.  
But I don’t fully understand it myself.  
Where should someone go looking if they wanted to understand what is going on with these?

---

<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:** [September 19, 2020, 7:52am UTC](https://discourse.julialang.org/t/how-keyword-arguments-kwfuncs-work/46840/2 "2020-09-19T07:52:10Z")

</div>

There is a short section about this in the devdocs:

[https://docs.julialang.org/en/v1.6-dev/devdocs/functions/#Keyword-arguments](https://docs.julialang.org/en/v1.6-dev/devdocs/functions/#Keyword-arguments)
