Hello. I’m looking for some guidance on a design decision to make. I have an algorithm which makes use of 10 to 20 specialized function that are called repeatedly, however, none of the functions are known until the necessary info is supplied at runtime. One strategy is to generate the code and cache the functions for later which is what the existing codebase does. Generating the AST for the function requires running expensive steps (i.e. graph algorithms), so I am unsure if there is even an alternative route besides eval-ing and storing the functions for reuse. Moreover I don’t think I can take a memoization route since the procedures are inherently stochastic. I have a couple of questions
- In similar scenarios where the functions ought to be stored somehow, what do people usually do? Do you do as I explained above, or something better? Are there example packages that run into similar design choices?
- Would generated functions work here? I also do not wish to pollute the namespace, so it seems I need anonymous functions. Is
eval
the go-to here?eval
ing these functions sounds like a type unstable mess . - How could I make sensible stack traces for the user if the code is generated?