[IPython-dev] Multiple outputs per input line
Mon Mar 14 03:11:48 CDT 2011
On Sun, Mar 13, 2011 at 10:32 PM, Brian Granger <firstname.lastname@example.org> wrote:
> I think that would get quite difficult. Mathematica's notion of
> output is very specific and concrete (they basically trigger a
> displayhook on every assignment). Our notion of "output" now is very
> dynamic - especially when you mix multiple frontends into the picture.
Remember, we're talking here about the outputs that get produced by
the displayhook, for those we do have numbers we can track (because
they stem from sys.displayhook firing). You're completely correct
that we can't number display side effects, like print statements or
any of the products of the new display system. But the return value
of computations, which is what Out[N] contains, we can track.
The logic for getting mathematica-like numbering is pretty easy:
- prior to code execution, the kernel sets an offset in the display hook to 0.
- on each call to displayhook, it does:
execution_counter += offset
With this, in all cases where only a single call is made to
displayhook get matching numbers, but if a displayhook fires multiple
times for a single input, then the counter is incremented accordingly.
This would let us have always unambiguous storage of outputs by number
even if multiple outputs were produced. The only change would be that
in such a scenario, the next input wouldn't be 'previous+1' but
instead it would be incremented by as many outputs as came out.
Because Python isn't a purely functional language, we'll always have a
distinction between the Out things that we can see go by on
displayhook and other uncontrolled side-effects (prints, plots, etc).
But so far, having numbered outputs for functional results has served
us well, so this would simply be a matter of refining that to better
handle the multi-output cases (which today we don't handle very well,
as Thomas discovered).
More information about the IPython-dev