Best way to update parameter values in a temporary module

jinml
Fri, 08 Jul 2022 20:12:48 +0000
General Usage

I am a Julia user mostly interested in numerical prototyping, where I have constant need to work with a large collection of custom functions that are related to each other, but far from being ready to define a package. I currently wrap the whole collection of codes in a temporary module in a .jl file in my search path to allow Revise detect any changes. That worked fine but pretty awkward.

Often times I need to quickly change certain values within the module while working in a REPL to test these changes on-spot. My question is how to do this more efficiently from REPL without constantly changing the source code. I could write a function like this to automatically go through a large number of param values and check the results in a loop.

module tempModule
...
... some_code_using_`param` ...
...
function change_param(param_new)
global param=param_new
... update_module ...
end
...
end #module

According to this thread, global variables wrapped in a function (or module, supposedly) should be efficient. However, I know that using global variables are generally discouraged.
Is there a better way of doing this without changing the source code?

5 posts - 2 participants