Ok, probably I’ll have to start one step before: Can I somehow compile methods into my sysimage that are defined by a script (or in the REPL), not in a module / package?
I just tested having a fully code-generated method defined in a module, e.g.
fun_name = :myfun
@eval export $fun_name
eval_code_gen(k) = :($(k) + $(k)*x^2 + $(k)*x^3)
named_function_gen(code, name) = :( $name(x) = $code )
(1.2, 0.3, 0.54) |> eval_code_gen |> c -> named_function_gen(c, fun_name) |> eval
end # Mytest
and it works fine (which is nice per se) and
myfun can be compiled into the system image (which is kinda obvious, since the module / package can be used as usual).
Now, the implementation above makes no sense; since everything is hardcoded, a plain function could be used. But my use case is more like if there was this method defined in the module:
make_named_function(k, fun_name) = k |> eval_code_gen |> c -> named_function_gen(c, fun_name)
It’s a “generator” for a function for which I can specify (some) of its parameters. In the REPL or in a script it could be used like so:
make_named_function((1.4, -0.3, 0.33), :mycustomfun) |> eval
So my question is whether I can compile
mycustomfun, defined in a plain script or in a REPL, into the system image? The use case is to have some external automation (think CMake / CTest) using several of those functions (with different “fixed” parameters
k) in a vast amount of tests (parameter sweeps etc.) during which only
x needs to be changed. Or, let the function be an entire mathematical model of a physical process PLUS its simulation for some scenario… and this simulation is used in the backend of an interactive “simulation web app”.
It would be nice if the to-be-compiled functions could be generated “on-the-fly” / dynamically, not in a module. And no, closures are not an option in the actual application, since “structural” parameters are included in
k, which, for example, are used to construct tuples to collect / reorder values without dynamic memory allocation, greatly speeding up things…