Passing locally defined function

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

using ThreadTools

do_it(a, b, c, d) = a + b * c + d
function try_it()
        # 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])

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.

1 Like

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


on thanks, should have crossed my mind

1 Like