# Passing locally defined function

**URL:** <https://discourse.julialang.org/t/passing-locally-defined-function/31846>\
**Category:** General Usage\
**Tags:** question\
**Created:** [December 4, 2019, 10:58am UTC](https://discourse.julialang.org/t/passing-locally-defined-function/31846 "2019-12-04T10:58:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![racinmat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/racinmat/32/11715_2.png) [@racinmat](https://discourse.julialang.org/u/racinmat)\
**Post date:** [December 4, 2019, 10:58am UTC](https://discourse.julialang.org/t/passing-locally-defined-function/31846/1 "2019-12-04T10:58:39Z")

</div>

Hi, I have a function with local variable, which I want to apply for each element in an array, in parallel manner. I am using ThreadTools library.

Assuming following code

```julia
using ThreadTools

do_it(a, b, c, d) = a + b * c + d
function try_it()
	b=5
        c=6
        d=7
        # following code works as expected
	tmap(x->do_it(x, b, c, d), [1, 2, 3, 4])
        # but I want to do this, so I don't have to pass the variables which are not changing here explicitly
	do_it(a) = do_it(a, b, c, d)
	tmap(do_it, [1, 2, 3, 4])
end

```

Generally, if there is any way how to get the passing b, c, d out of the tmap, so the code would be more readable, I’m for it.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [December 4, 2019, 12:35pm UTC](https://discourse.julialang.org/t/passing-locally-defined-function/31846/2 "2019-12-04T12:35:52Z")

</div>

It works if you use a different name for the global and local functions. Or qualify the global with the module name.

---

<div class="post-metadata">

**Author:** ![racinmat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/racinmat/32/11715_2.png) [@racinmat](https://discourse.julialang.org/u/racinmat)\
**Post date:** [December 4, 2019, 1:23pm UTC](https://discourse.julialang.org/t/passing-locally-defined-function/31846/3 "2019-12-04T13:23:04Z")

</div>

on thanks, should have crossed my mind
