# How to conveniently pass arguments from a function to another?

**URL:** <https://discourse.julialang.org/t/how-to-conveniently-pass-arguments-from-a-function-to-another/114385>\
**Category:** General Usage\
**Tags:** question, function\
**Created:** [May 17, 2024, 4:50am UTC](https://discourse.julialang.org/t/how-to-conveniently-pass-arguments-from-a-function-to-another/114385 "2024-05-17T04:50:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![WuSiren](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wusiren/32/42529_2.png) [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Post date:** [May 17, 2024, 4:50am UTC](https://discourse.julialang.org/t/how-to-conveniently-pass-arguments-from-a-function-to-another/114385/1 "2024-05-17T04:50:10Z")

</div>

```julia
function f(x=1, y=2, z=3; a=1, b=2, c=3)
    # How do I know if a/b/c is assigned a value?
    2 * g(x, y, z; a=a, b=b, c=c) # Do I have to pass the arguments one by one to g?
end

function g(x=1, y=2, z=3; a=1, b=2, c=3)
    [a, b, c]' * [x, y, z]
end

```

Q1: How do I know if some keyword argument is assigned a value in the definition of a function?

Q2: Do I have to pass the arguments one by one to another function? I mean is there any convenient method to extracting all the input arguments when defining a function?

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [May 17, 2024, 5:02am UTC](https://discourse.julialang.org/t/how-to-conveniently-pass-arguments-from-a-function-to-another/114385/2 "2024-05-17T05:02:44Z")

</div>

```julia
function f(args...; kwargs...)
    # if you refer to a kwarg explicitly, they must br assigned or error
    2 * g(args...; kwargs...)
 # You can slurp amd splat them
end

function g(x=1, y=2, z=3; a=1, b=2, c=3)
    [a, b, c]' * [x, y, z]
end

```

```julia-repl
julia> f(1,2,3; a=10)
46

```

A1. If you assign a keyword argument a default value such as `nothing` you can check for `nothing` to see if it has the default value or another value.

A2. You can slurp and splat the arguments as above.

---

<div class="post-metadata">

**Author:** ![WuSiren](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wusiren/32/42529_2.png) [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Post date:** [May 17, 2024, 5:07am UTC](https://discourse.julialang.org/t/how-to-conveniently-pass-arguments-from-a-function-to-another/114385/3 "2024-05-17T05:07:50Z")

</div>

> [@mkitti](#):
>
> You can slurp and splat the arguments as above.

This means I can’t explicitly show the input arguments of the outer level function `f` in its definition?

---

<div class="post-metadata">

**Author:** ![WuSiren](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wusiren/32/42529_2.png) [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Post date:** [May 17, 2024, 5:10am UTC](https://discourse.julialang.org/t/how-to-conveniently-pass-arguments-from-a-function-to-another/114385/4 "2024-05-17T05:10:40Z")

</div>

Can I add more keywords to `f` then?

```julia
function f(args...; d=1, kwargs..., e=2)
    # if you refer to a kwarg explicitly, they must br assigned or error
    2 * g(args...; kwargs...) * d * e
end

```

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [May 17, 2024, 5:31am UTC](https://discourse.julialang.org/t/how-to-conveniently-pass-arguments-from-a-function-to-another/114385/5 "2024-05-17T05:31:04Z")

</div>

Yes, but they have to come first.

```julia
function f(args...; d=1, e=2, kwargs...)
    # if you refer to a kwarg explicitly, they must br assigned or error
     2 * g(args...; kwargs...) * d * e
end

```
