[IPython-dev] Execution semantics and how to set them
zaki.mughal at gmail.com
Sun Jan 25 14:16:59 EST 2015
On 2015-01-25 at 10:57:01 -0800, Thomas Kluyver wrote:
> Hi Zaki,
> On 25 January 2015 at 10:26, Zakariyya Mughal <zaki.mughal at gmail.com> wrote:
> > I'm a language kernel author and I'm looking at the execution semantics
> > document[^1] where I see a reference to the "single" execution mode.
> > It says that the code
> > for i in range(10):
> > i**2
> > running in "single" mode would display 10 lines.
> > I looked through the IPython source and I see that the execution
> > semantics are set as an argument for `run_ast_nodes`[^2], but I see no
> > way that the given for-loop would give multiple outputs unless the
> > `interactivity` parameter is set to `last` or `all`.
> First, let me emphasise that all of this is only relevant for executing
> Python code. If you're building a kernel for another language, you should
> ignore all of this. That documentation page is only about IPython's own
> The three modes described on that page (exec, eval, single) are compilation
> modes of Python itself, passed as arguments to the built-in compile()
> The parameter passed to our run_ast_nodes() method (which can be all, none,
> last or last_expr) controls which of a list of AST nodes are compiled in
> 'single' mode. Our default of last_expr is chosen specifically so that the
> for loop example above does not produce output, because we think that's
> more likely to be annoying than useful. There is no way to control this
> from the frontend, and I don't think we have any intention to add such a
> For your own kernel, you should implement whatever display of output makes
> sense given the language and the likely users. For Python, we decided that
> it makes sense to automatically display the result of the last statement if
> that statement is an expression, and implemented that using the details
> described above. For R, I implemented similar behaviour based on the
> evaluate package by creating an output_handler with a value= parameter.
I see. It's easy enough to just call print if a user wants that.
> Which language are you working on a kernel for?
I wrote one for Perl <https://github.com/zmughal/p5-Devel-IPerl>.
I released it back in August and I've been meaning to write a blog post
and announce it more widely, but I first wanted to make sure it
- Zaki Mughal
> IPython-dev mailing list
> IPython-dev at scipy.org
More information about the IPython-dev