Weird behavior: `UndefVarError:` module function needs to be called with ModuleName.function

This has come up a couple times for me but I’m daunted by the idea of getting an MRE because it is rare.

I write a non-exported helper function or method extension inside a module and it is undefined unless I call it with the full ModuleName.function even though it is only being used inside the module. Obviously it is easy to get the code to run, but it is annoying, and makes me feel like I am missing something.

here is code that errors:

module EscapeSimulator
#....

function equilibrium_sampler(θ, ab_profile_list)
    mapreduce( y -> map(x-> WrightSampler((x .* θ)...), y), vcat, ab_list)
end

function initialize_viral_population(θ::Float64, ab_ist)
    equilibrium_sampler = equilibrium_sampler(θ, ab_list)
    return equilibrium_sampler
end

#...
end

But this kind of thing works

module EscapeSimulator
#....

function equilibrium_sampler(θ, ab_list)
    mapreduce( y -> map(x-> WrightSampler((x .* θ)...), y), vcat, ab_list)
end

function initialize_viral_population(θ, ab_list)
    equilibrium_sampler = EscapeSimulator.equilibrium_sampler(θ, ab_list)
   # I need to specify the module -^ ?!
    return equilibrium_sampler
end

#...
end

Again this is not meant to be an MWE, I’m just wondering if other people have seen this kind of lost variable effect inside their modules and what it means. In the meantime I’ll try and get an MWE and will post an answer if I figure it out.

Isn’t the problem that you are redefining this name here, thus criating an ambiguity ?

2 Likes

Oh geeze yeah I guess maybe it’s calling the local variable I just created. :crazy_face:

1 Like