Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The function Nest[] must store the temporary values in the memory somewhere (those values that would form the entries of the list which is returned by the equivalent NestList function).

Does anyone know if there is a way to access said values in an interrupted evaluation (using a kernel subsession)?

Alternatively, is there a way to know all temporary variables currently in use and to print out their values?

share|improve this question
So you want to manualy abort Nest when you see that current value is what you want? – Kuba Aug 19 '13 at 9:18
Probably some sort of Reap and Sow combination but some more details would be welcome. – Mike Honeychurch Aug 19 '13 at 9:25
You can assign a value to an arbitrary control variable in the function you are Nesting and display that any way you like... In any case, some code/MWE would be very helpful. – Yves Klett Aug 19 '13 at 9:27
Let's say I started an iterative computation, e.g. an optimization and it takes too long. Instead of waiting until it's finished (if it ever does), I want to check where it currently is. – S.Surace Aug 19 '13 at 11:33

I don't know about temporary values, but if you want to monitor the progression of Nest you could use the following:

intensiveCalculation[x_] := (Pause[0.5]; x + 1)

Nest[(PrintTemporary[#]; #) &@ intensiveCalculation[#] &, 1, 5]
share|improve this answer

If I understand you question correctly, you want to run a Nest command. In cases where the Nest takes a long time you'd like to abort (or suspend) the command and then through an interactive debugging session see the values obtained thus far. If this is what you are asking, to the best of my knowledge this is not possible. You need to add code (like Sow) prior to the execution.

share|improve this answer
Does Reap also work for interrupted evaluations? – Yves Klett Aug 19 '13 at 15:57
@YvesKlett, I have never tried that. – user21 Aug 19 '13 at 16:33
Yes, that's what I want to do! Thanks! – S.Surace Aug 20 '13 at 10:41

An alternative using Dynamic to give you a constantly updated progress indicator:

intensiveCalculation[x_] := (Pause[0.5]; x + 1)


Nest[(y = #; intensiveCalculation[#]) &, 1, 10]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.