# Passing keyword arguments to nested functions | or how to use macros to define a function whose kwargs are those of their inner function calls

**URL:** <https://discourse.julialang.org/t/passing-keyword-arguments-to-nested-functions-or-how-to-use-macros-to-define-a-function-whose-kwargs-are-those-of-their-inner-function-calls/88671>\
**Category:** General Usage\
**Tags:** macros, kwargs, ast\
**Created:** [October 13, 2022, 2:48pm UTC](https://discourse.julialang.org/t/passing-keyword-arguments-to-nested-functions-or-how-to-use-macros-to-define-a-function-whose-kwargs-are-those-of-their-inner-function-calls/88671 "2022-10-13T14:48:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![abelsiqueira](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abelsiqueira/32/47269_2.png) [@abelsiqueira](https://discourse.julialang.org/u/abelsiqueira)\
**Post date:** [October 13, 2022, 2:48pm UTC](https://discourse.julialang.org/t/passing-keyword-arguments-to-nested-functions-or-how-to-use-macros-to-define-a-function-whose-kwargs-are-those-of-their-inner-function-calls/88671/1 "2022-10-13T14:48:41Z")

</div>

Important: I am trying to figure this out to compare to a Python approach, which I mention in the second part of the question.

Suppose I have two functions, `foo` and `bar`, whose keyword argument I don’t know or care.  
Suppose I want to write a function that calls these two using arbitrary keyword arguments.  
For instance:

```julia
# Explicit kwargs
function solve_and_plot(problem; tol=1e-4, color=:red)
    solve(problem, tol=tol)
    plot(problem, color=color)
end

# More generic
function solve_and_plot(problem; kwargs...)
    solve(problem; kwargs...)
    plot(problem; kwargs...)
end

```

Is there a way to do it **magically**?

I normally solve this using Dicts for each function, what other approaches do you do?

* * *

The Python approach to do it magically is using decorators to change the AST.  
Assuming there is no current way to do it implemented, I though I would try to do it to learn more about AST and Macros.  
Using MacroTools, it is almost feasible at my current understanding, but I am missing **how to find the (types and) default values of keyword arguments**.  
Answers to this question instead are also appreciated.

Thanks in advance.
