# Please show me how to pass 2 tuples as arguments to a function

**URL:** <https://discourse.julialang.org/t/please-show-me-how-to-pass-2-tuples-as-arguments-to-a-function/21841>\
**Category:** New to Julia\
**Created:** [March 13, 2019, 11:23pm UTC](https://discourse.julialang.org/t/please-show-me-how-to-pass-2-tuples-as-arguments-to-a-function/21841 "2019-03-13T23:23:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![samq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/samq/32/47935_2.png) [@samq](https://discourse.julialang.org/u/samq)\
**Post date:** [March 13, 2019, 11:23pm UTC](https://discourse.julialang.org/t/please-show-me-how-to-pass-2-tuples-as-arguments-to-a-function/21841/1 "2019-03-13T23:23:29Z")

</div>

While studying neural networks, I have the following function defined.

```julia
function update_loss!()
     push!(train_loss, L(trainbatch...).data)
     push!(test_loss, L(testbatch...).data)
     @printf("train loss = %.2f, test loss = %.2f\n", train_loss[end], test_loss[end]) 
end

```

I use the function in the following statement and it works just fine:

```julia
@time Flux.train!(L, params(model), Iterators.repeated(trainbatch, 1000), opt;
            cb = Flux.throttle(update_loss!, 4))

```

The update\_loss! function currently uses trainbatch and testbatch without them being passed as arguments; two tuples that are defined outside the function; but what I want is to pass the tuples as arguments to the update\_loss! function so I can use it more generically; with any two tuples.

```julia
julia> typeof(trainbatch)
Tuple{Array{Float64,2},Flux.OneHotMatrix{Array{Flux.OneHotVector,1}}}

```

I’ve googled a lot on this without success; using several “…” tries, but I usually get a:

```julia
"MethodError: objects of type Nothing are not callable"

```

---

<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:** [March 14, 2019, 12:17am UTC](https://discourse.julialang.org/t/please-show-me-how-to-pass-2-tuples-as-arguments-to-a-function/21841/2 "2019-03-14T00:17:28Z")

</div>

Just use a closure to pass additional parameters to a callback function.

---

<div class="post-metadata">

**Author:** ![jandehaan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jandehaan/32/6805_2.png) [@jandehaan](https://discourse.julialang.org/u/jandehaan)\
**Post date:** [March 14, 2019, 12:20am UTC](https://discourse.julialang.org/t/please-show-me-how-to-pass-2-tuples-as-arguments-to-a-function/21841/3 "2019-03-14T00:20:07Z")

</div>

Consider using a closure (a function that returns a function).

```julia
function update_loss!(trainbatch, testbatch)
    return () -> begin 
          push!(train_loss, L(trainbatch...).data)
          push!(test_loss, L(testbatch...).data)
          @printf("train loss = %.2f, test loss = %.2f\n", train_loss[end], test_loss[end]) 
    end
end

cb = Flux.throttle(update_loss!(trainbatch, testbatch), 4))

```

---

<div class="post-metadata">

**Author:** ![samq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/samq/32/47935_2.png) [@samq](https://discourse.julialang.org/u/samq)\
**Post date:** [March 14, 2019, 12:42am UTC](https://discourse.julialang.org/t/please-show-me-how-to-pass-2-tuples-as-arguments-to-a-function/21841/4 "2019-03-14T00:42:59Z")

</div>

@stevengj Thank you! This was hard to glean without your help!

---

<div class="post-metadata">

**Author:** ![samq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/samq/32/47935_2.png) [@samq](https://discourse.julialang.org/u/samq)\
**Post date:** [March 14, 2019, 12:57am UTC](https://discourse.julialang.org/t/please-show-me-how-to-pass-2-tuples-as-arguments-to-a-function/21841/5 "2019-03-14T00:57:08Z")

</div>

@jandehann Thank you for such a clear explanation!
