# Kwargs unexpected (?) error

**URL:** <https://discourse.julialang.org/t/kwargs-unexpected-error/122089>\
**Category:** General Usage\
**Tags:** kwargs\
**Created:** [October 31, 2024, 5:03pm UTC](https://discourse.julialang.org/t/kwargs-unexpected-error/122089 "2024-10-31T17:03:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@aris](https://discourse.julialang.org/u/aris)\
**Post date:** [October 31, 2024, 5:03pm UTC](https://discourse.julialang.org/t/kwargs-unexpected-error/122089/1 "2024-10-31T17:03:44Z")

</div>

I ran across the following while writing some code.

```julia
function foo( x::Vector, y::Vector; cond=true)

    if cond
        return x .- y
    end
end

function bar(x, y; kwargs...)
    return foo(x, y, kwargs...)
end

# These work fine
foo(rand(10), rand(10))
foo(rand(10), rand(10), cond=true)
bar(rand(10), rand(10))

# This does not
bar(rand(10), rand(10), cond=true)

```

The error is:

```julia
 MethodError: no method matching foo(::Vector{Float64}, ::Vec
tor{Float64}, ::Pair{Symbol, Bool})
The function `foo` exists, but no method is defined for this combin
ation of argument types.

```

Would someone please explain why this happens here, and what would be the correct way to define the functions above?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [October 31, 2024, 5:25pm UTC](https://discourse.julialang.org/t/kwargs-unexpected-error/122089/2 "2024-10-31T17:25:49Z")

</div>

> [@aris](#):
>
> `return foo(x, y, kwargs...)`

Here, you are splatting `kwargs` as positional arguments. To splat them as keyword arguments, put them after a semicolon: `foo(x, y; kwargs...)`

In Julia, keyword and positional arguments are completely distinct (unlike e.g. Python).

---

<div class="post-metadata">

**Author:** ![aris](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@aris](https://discourse.julialang.org/u/aris)\
**Post date:** [October 31, 2024, 8:14pm UTC](https://discourse.julialang.org/t/kwargs-unexpected-error/122089/3 "2024-10-31T20:14:48Z")

</div>

Makes perfect sense, somehow I missed this detail.

Thanks a lot Steven!
