# Monitoring progress of nested function calls

I wrote some code where my output function is defined in terms of various functions, themselves defined in terms of various functions, schematically like $$f(x) = g(h(x))$$, $$h(x) = k(m(x))$$, etc., as you do.

For a given x, the evaluation of each of these functions might take a while, and I would like to keep an eye on the stage my computation is at, e.g. (temporarily) printing "evaluating h", when $$h(k)$$ starts being computed, similarly to how Monitor[] does this for e.g. the iterator in a table.

I am looking for tips on how to do this nicely.

Currently I am defining e.g.

h[x_] := h[x_] = { PrintTemporary["evaluating h"] , (actual expression for the function) }[[2]]


which does the job. The construction with the list seems rather roundabout, but I am not sure how else to make sure the print happens every time the function is called (with a distinct argument). Is there a better, optimal, or even built-in option for this?

• Perhaps Progress Indicator for NestList is what you are looking for Aug 14 '20 at 13:07
• Don't use List brackets, use parentheses to enclose the compound expression: h[x_] := h[x] = (PrintTemporary[StringForm["Evaluating h[]", x]]; calculation ); Aug 14 '20 at 13:26
• Thanks a lot @BobHanlon! That is the appropriate way to implement what I tried to do above. I had a feeling something was off, but could not remember for the life of me how to do it.. Aug 14 '20 at 13:44
• Thanks also @UlrichNeumann. I think the NestList progress indicator would have been very useful if my nesting/functions were indexed, but that is not the structure I am currently dealing with. Aug 14 '20 at 13:47
• I would of course still be interested in solutions that avoid defining my individual functions to signal themselves.. Aug 14 '20 at 13:48