michaelb/sniprun

A Feature Question, about live mode.

PorcoRosso85 opened this issue · 6 comments

I've read this doc about live mode, https://michaelb.github.io/sniprun/sources/README.html#live-mode

Is this mode like this gif image?
I mean "like" is similar.
In this gif image, definition of print function shows us its result/stdout immediately.
image

I'm searching the way for us to make debug easily, so I met your SnipRun.
If yes, sniprun will make us easy to dev.

Thanks.

Tldr: not as good

It's more limited feature-wise (but is compatible with more languages), and has major drawbacks that don't make it as usable:

  • only reevaluate the line you're modifying, not the whole file
  • needs a solid REPL (live mode in Mathematica will crash very quickly) that can eat incomplete code. (Or else - non-repl mode - you're limited to evaluate self-contained lines, which is not very useful)
  • may introduce side effects: eg typing

a = 1
a = a + 1 + 1
print (a)

will output '4' because an intermediate a = a+1 was a correct expression

Thanks.
I maybe undestand why yours reevaluate modified line only, and why we require REPL like what you said.

https://michaelb.github.io/sniprun/sources/README.html#support-levels-and-languages
If only "REPL Capabilities" is true, live-mode is available?

And I toggled live-mode enable, then I misunderstood that print function will work if I toggle it.
But I need to run SnipRun manually.
Excuse me and please let me know where I have to read.

If only "REPL Capabilities" is true, live-mode is available?

No, live mode is available for every language, but isn't very useful in practice unless you use languages that have REPL support.

with live mode enabled, you should be able to type (eg, in python, and no need to enable repl for such a simple example)

print(4+6)

and as soon as you type the closing parenthesis, sniprun should display '14'

Live-mode documentation is here:

https://michaelb.github.io/sniprun/sources/README.html#live-mode

It works!
image

Thanks.

another function

print( a + b )

is not working, is this why because SnipRun only reevaluate the line you're modifying, not the whole file?

indeed. It's not displaying anything because it's evaluating to an error: (probably in the lines of 'variable a not defined'), and errors are hidden by default for live mode evals. See the 'live_display' config key.

For print(a+b) to display the result as you're typing, you'd have to work in a language that support REPL, with REPL activated (not always enabled by default) and whose REPL doesn't crash when you send too much strange & incomplete code.

Then you'd have to :SnipRun (or edit/type because live mode) the lines:
a=5
b=2

At that point, print(a+b) will (should) work

I'd suggest using Python3_fifo for python:

require('sniprun').setup({
    selected_intepreters={'Python3_fifo'},
    live_mode_toggle='enable'
})

but as always pick what's working best for you. If the Python3_original with REPL enabled works as well, great for you!

Thanks, I'll try what you tell me.