# How to pass first argument of a function as default and only input second argument

**URL:** <https://discourse.julialang.org/t/how-to-pass-first-argument-of-a-function-as-default-and-only-input-second-argument/24426>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [May 21, 2019, 12:09pm UTC](https://discourse.julialang.org/t/how-to-pass-first-argument-of-a-function-as-default-and-only-input-second-argument/24426 "2019-05-21T12:09:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jaime](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jaime/32/8542_2.png) [@Jaime](https://discourse.julialang.org/u/Jaime)\
**Post date:** [May 21, 2019, 12:09pm UTC](https://discourse.julialang.org/t/how-to-pass-first-argument-of-a-function-as-default-and-only-input-second-argument/24426/1 "2019-05-21T12:09:14Z")

</div>

function addremove( x=100, y=10)  
x+y, x-y  
end

I can put second argument as default value by  
addremove(10)  
and this will result (20, 0)

but how can I put first argument as default and input only second argument?

I remember some functions in other modules were defined in such a way and worked well.

---

<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:** [May 21, 2019, 12:47pm UTC](https://discourse.julialang.org/t/how-to-pass-first-argument-of-a-function-as-default-and-only-input-second-argument/24426/2 "2019-05-21T12:47:28Z")

</div>

Consider using [keyword arguments](https://docs.julialang.org/en/v1/manual/functions/#Keyword-Arguments-1).

Also, please [quote your code](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530).

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [May 21, 2019, 1:03pm UTC](https://discourse.julialang.org/t/how-to-pass-first-argument-of-a-function-as-default-and-only-input-second-argument/24426/3 "2019-05-21T13:03:08Z")

</div>

If you want to keep this positional then you can define `addremove(x, y)` without defaults and also define this:

```julia
addremove(y) = addremove(default_x, y)

```

All that default argument syntax does is define such methods for you.

---

<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:** [May 21, 2019, 1:26pm UTC](https://discourse.julialang.org/t/how-to-pass-first-argument-of-a-function-as-default-and-only-input-second-argument/24426/4 "2019-05-21T13:26:32Z")

</div>

This is generally only used when the first argument(s) have a different type (eg `rand`).

While there is nothing wrong with it _per se_, it may be somewhat confusing and unexpected for arguments of the same type.
