# Concise call keyword arg with default by conditional

**URL:** https://discourse.julialang.org/t/concise-call-keyword-arg-with-default-by-conditional/90716
**Category:** General Usage
**Tags:** argument, functions, keywords
**Created:** [November 23, 2022, 3:21pm UTC](https://discourse.julialang.org/t/concise-call-keyword-arg-with-default-by-conditional/90716 "2022-11-23T15:21:23Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![halleysfifthinc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/halleysfifthinc/32/206280_2.png) [@halleysfifthinc](https://discourse.julialang.org/u/halleysfifthinc)
#### Post date: [November 23, 2022, 5:04pm UTC](https://discourse.julialang.org/t/concise-call-keyword-arg-with-default-by-conditional/90716/3 "2022-11-23T17:04:05Z")

</div>

> [@taotree](#):
>
> Either I have to write a conditional at the call site, or have function A have both a default value for the argument (I need that for other cases) and convert a nothing value to that default value inside the function.

The latter is the idiomatic/Julian solution: assign `kwarg=nothing` in the signature, and in the function body, and set `kwarg` to its default value if `isnothing(kwarg)`. `nothing` serves as an “unset” sentinel value that doesn’t special case a regular value (e.g. using `-1` as the “unset” value). `nothing` could even still be used as a valid value by giving the `kwarg` as `Some(nothing)`.

```julia
function A(x; kwarg=nothing)
    if isnothing(kwarg)
        kwarg = 100
    end
    # rest of function
end

```

---

_[View the full topic](https://discourse.julialang.org/t/concise-call-keyword-arg-with-default-by-conditional/90716)._
