# Is it possible to check if a function has been called with a keyword argument explicitly?

**URL:** https://discourse.julialang.org/t/is-it-possible-to-check-if-a-function-has-been-called-with-a-keyword-argument-explicitly/90812
**Category:** General Usage
**Created:** [November 25, 2022, 2:39pm UTC](https://discourse.julialang.org/t/is-it-possible-to-check-if-a-function-has-been-called-with-a-keyword-argument-explicitly/90812 "2022-11-25T14:39:04Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [November 25, 2022, 2:39pm UTC](https://discourse.julialang.org/t/is-it-possible-to-check-if-a-function-has-been-called-with-a-keyword-argument-explicitly/90812/1 "2022-11-25T14:39:04Z")

</div>

Is there a way to determine if a keyword argument with a default value has been explicitly given or the default has been used ?

```julia
function foo(;karg1::Int64=3)
    # if foo has been called with karg1 explicitly then... else...
end

```

I know I can use `kwargs...` and then check the dictionary, but my actual function has several default keyword arguments and I am interested in checking just one…

(I bet “no” but… never know!)

---

<div class="post-metadata">

### Author: ![colleybrb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/colleybrb/32/44529_2.png) [@colleybrb](https://discourse.julialang.org/u/colleybrb)
#### Post date: [November 25, 2022, 4:39pm UTC](https://discourse.julialang.org/t/is-it-possible-to-check-if-a-function-has-been-called-with-a-keyword-argument-explicitly/90812/2 "2022-11-25T16:39:37Z")

</div>

If I’m getting the jist of what you want. I think multiple dispatch with varied input defined as different functions should meet your requirements.

---

<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 25, 2022, 4:48pm UTC](https://discourse.julialang.org/t/is-it-possible-to-check-if-a-function-has-been-called-with-a-keyword-argument-explicitly/90812/3 "2022-11-25T16:48:35Z")

</div>

My suggestion [here](https://discourse.julialang.org/t/concise-call-keyword-arg-with-default-by-conditional/90716/3) would allow this, but could be considered to make your function “messier”.

```julia
function A(x; karg1=nothing)
    if isnothing(karg1)
        karg1 = 3
    else
        # karg1 was explicitly given
    end
    # rest of function
end

```

And you could even disambiguate whether the keyword argument was explicitly given with the default value, e.g.

```julia
function A(x; karg1=nothing)
    if isnothing(karg1)
        karg1 = 3
    elseif karg1 == 3
        # karg1 was explicitly given as the default value
    end
    # rest of function
end

```

---

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [November 25, 2022, 4:51pm UTC](https://discourse.julialang.org/t/is-it-possible-to-check-if-a-function-has-been-called-with-a-keyword-argument-explicitly/90812/4 "2022-11-25T16:51:46Z")

</div>

yep, that’s exactly the “solution” I ended up using…
