Creating an anonymous function at the local level. Conflict with const resulting in performance issues

Thanks!

I oversimplified the code though. The call to sim_function happens deeper in the call stack, not at the top level in the iteration loop. So it’s within a function that is called within the iteration loop of the simulation.

I guess I’ll need to drop the anonymous function solution and store the data in the model (in the full implementation I can store arbitrary data in the model). I just found the anonymous function solution more elegant.