# Passing values to function arguments using Dict?

**URL:** <https://discourse.julialang.org/t/passing-values-to-function-arguments-using-dict/45758>\
**Category:** New to Julia\
**Created:** [August 29, 2020, 5:44pm UTC](https://discourse.julialang.org/t/passing-values-to-function-arguments-using-dict/45758 "2020-08-29T17:44:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![varun7rs](https://avatars.discourse-cdn.com/v4/letter/v/c2a13f/32.png) [@varun7rs](https://discourse.julialang.org/u/varun7rs)\
**Post date:** [August 29, 2020, 5:44pm UTC](https://discourse.julialang.org/t/passing-values-to-function-arguments-using-dict/45758/1 "2020-08-29T17:44:47Z")

</div>

Hi,  
I have a problem where a function already defined in Julia has several keyword arguments. Now, to pass in values to these arguments, I’ve got to do something like the following

> dummyFn(3, 4; key1=6, key2=9, key3=6, key4=5)

I’d like to be able to pass values to these keyword arguments either as a tuple or as a dict. For example, I can create a dictionary named vals and pass the dictionary to the dummyFn without necessarily referring to the keyword arguments

> vals = Dict(:key1 =\> 6, :key2=\> 9, :key3 =\> 6, :key4 =\> 5)

> dummyFn(3, 4, vals)

This way, I can plug in the dictionary everytime I call the dummyFn in my code without needing to referring to the keyword arguments. Could this be possible in Julia?

---

<div class="post-metadata">

**Author:** ![Vasily\_Pisarev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vasily_pisarev/32/7929_2.png) [@Vasily\_Pisarev](https://discourse.julialang.org/u/Vasily_Pisarev)\
**Post date:** [August 29, 2020, 5:55pm UTC](https://discourse.julialang.org/t/passing-values-to-function-arguments-using-dict/45758/2 "2020-08-29T17:55:28Z")

</div>

Yes, it is possible with the “splat” operator: `dummyFn(3, 4; vals...)` will do the trick.  
Note, however, that using a named tuple for `vals` will be more performant if you don’t need to change the values associated with the keys:

```julia
vals = (key1 = 6, key2= 9, key3 = 6, key4 = 5)
dummyFn(3, 4; vals...)

```

---

<div class="post-metadata">

**Author:** ![varun7rs](https://avatars.discourse-cdn.com/v4/letter/v/c2a13f/32.png) [@varun7rs](https://discourse.julialang.org/u/varun7rs)\
**Post date:** [August 29, 2020, 6:05pm UTC](https://discourse.julialang.org/t/passing-values-to-function-arguments-using-dict/45758/3 "2020-08-29T18:05:08Z")

</div>

Thanks Vasily, but since I still work with Juliav0.6.3, creating a named tuple throws up an error. Is there a workaround? I tried using the splat operator in comination with a dictionary and it worked fine! Thanks again.

---

<div class="post-metadata">

**Author:** ![Vasily\_Pisarev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vasily_pisarev/32/7929_2.png) [@Vasily\_Pisarev](https://discourse.julialang.org/u/Vasily_Pisarev)\
**Post date:** [August 29, 2020, 6:13pm UTC](https://discourse.julialang.org/t/passing-values-to-function-arguments-using-dict/45758/4 "2020-08-29T18:13:29Z")

</div>

[NamedTuples.jl](https://github.com/JuliaData/NamedTuples.jl), I guess.

---

<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:** [August 29, 2020, 6:40pm UTC](https://discourse.julialang.org/t/passing-values-to-function-arguments-using-dict/45758/5 "2020-08-29T18:40:25Z")

</div>

> [@varun7rs](#):
>
> but since I still work with Juliav0.6.3,

Is there something in particular that holding you back? You’re missing out on a lot of great stuff, and that version is technically no longer supported. I understand upgrading can be hard sometimes, and pre-1.0 I remember it being hard to keep up, but things have been quite stable for the last 2 years, and only getting better

---

<div class="post-metadata">

**Author:** ![varun7rs](https://avatars.discourse-cdn.com/v4/letter/v/c2a13f/32.png) [@varun7rs](https://discourse.julialang.org/u/varun7rs)\
**Post date:** [August 29, 2020, 7:00pm UTC](https://discourse.julialang.org/t/passing-values-to-function-arguments-using-dict/45758/6 "2020-08-29T19:00:02Z")

</div>

Not really and I’d love to make the switch. As a part of this project I’m working on, I’ve continued using v0.6.3 from the beginning and since its nearing completion, I didn’t want to mess up the existing (lots of) code by upgrading to the newest version.
