# Dictionary with keywargs not working

**URL:** <https://discourse.julialang.org/t/dictionary-with-keywargs-not-working/101441>\
**Category:** New to Julia\
**Tags:** error, dictionary, function\
**Created:** [July 10, 2023, 4:26pm UTC](https://discourse.julialang.org/t/dictionary-with-keywargs-not-working/101441 "2023-07-10T16:26:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rgouveiamendes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rgouveiamendes/32/218636_2.png) [@rgouveiamendes](https://discourse.julialang.org/u/rgouveiamendes)\
**Post date:** [July 10, 2023, 4:26pm UTC](https://discourse.julialang.org/t/dictionary-with-keywargs-not-working/101441/1 "2023-07-10T16:26:31Z")

</div>

Hello!  
I have been struggling with a small issue when I pass a dictionary to a function with the keywargs values assigned.  
Here is minimum reproducible example:

```julia
function mySimpleFun(;
	T::Integer,	δ::Float64, σ::Float64, α::Float64
)
	sum = T + δ + σ + α
	return sum
end

attempt = Dict(
	:T => 200,
	:δ => 0.1,
	:σ => 0.2,
	:α => 0.4
)

mySimpleFun(; attempt)

```

I always get: `ERROR: UndefVarError: `T` not defined`  
In Pluto.jl, the message is different but similar: `UndefKeywordError: keyword argument 'T' not assigned`.

Am I doing something wrong?  
It would be very convenient to pass the same parameters to different models (defined as functions).

Thank you!

---

<div class="post-metadata">

**Author:** ![algunion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/algunion/32/51630_2.png) [@algunion](https://discourse.julialang.org/u/algunion)\
**Post date:** [July 10, 2023, 4:30pm UTC](https://discourse.julialang.org/t/dictionary-with-keywargs-not-working/101441/2 "2023-07-10T16:30:25Z")

</div>

Try to call your function using splatting: `mySimpleFun(; attempt...)`.

---

<div class="post-metadata">

**Author:** ![rgouveiamendes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rgouveiamendes/32/218636_2.png) [@rgouveiamendes](https://discourse.julialang.org/u/rgouveiamendes)\
**Post date:** [July 10, 2023, 4:32pm UTC](https://discourse.julialang.org/t/dictionary-with-keywargs-not-working/101441/3 "2023-07-10T16:32:04Z")

</div>

Thank you! It worked. Can you please give me a glimpse into why did it work?

---

<div class="post-metadata">

**Author:** ![algunion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/algunion/32/51630_2.png) [@algunion](https://discourse.julialang.org/u/algunion)\
**Post date:** [July 10, 2023, 4:36pm UTC](https://discourse.julialang.org/t/dictionary-with-keywargs-not-working/101441/4 "2023-07-10T16:36:37Z")

</div>

For now, please take a look [here](https://docs.julialang.org/en/v1/manual/faq/#What-does-the-...-operator-do?). (it seems up to date enough)

I’ll get back when I get some time and discuss the `Dict` usage specifically. But the above material should help anyway.

---

<div class="post-metadata">

**Author:** ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)\
**Post date:** [July 11, 2023, 2:09am UTC](https://discourse.julialang.org/t/dictionary-with-keywargs-not-working/101441/5 "2023-07-11T02:09:35Z")

</div>

Calling `mySimpleFun(; attempt)` would work for a function that had a single keyword arg named `attempt`. The function you wrote expects 4 kwargs called T, delta, sigma, and alpha. When you “splat” with `...`, that’s essentially unpacking your dictionary into its 4 constituent `key => value` pairs.

For the most part, Julia tries to avoid [DWIM](https://en.m.wikipedia.org/wiki/DWIM), so if you pass a single object when 4 were expected, you’ll get an error.
