1

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?

Stijn
  • 330
  • 1
  • 7
  • 2
    Perhaps Progress Indicator for NestList is what you are looking for – Ulrich Neumann Aug 14 '20 at 13:07
  • 2
    Don't use List brackets, use parentheses to enclose the compound expression: h[x_] := h[x] = (PrintTemporary[StringForm["Evaluating h[\`]", x]]; calculation );` – Bob Hanlon 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.. – Stijn 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. – Stijn Aug 14 '20 at 13:47
  • I would of course still be interested in solutions that avoid defining my individual functions to signal themselves.. – Stijn Aug 14 '20 at 13:48

0 Answers0