fonsp / Pluto.jl

🎈 Simple reactive notebooks for Julia
https://plutojl.org/
MIT License
5k stars 296 forks source link

Macro output: to terminal or to worksheet? #161

Closed MikaelSlevinsky closed 4 years ago

MikaelSlevinsky commented 4 years ago

A general inconsistency which affects macros is where to find the output: either in the worksheet or in the terminal which launched the Pluto runner. Examples include:

This may be related to the ways in which these macros are written regarding their displays. But is it reasonable for a Pluto user to not know a priori where the results of a macro will be displayed? (It's not something I can't get used to, by the way.)

fonsp commented 4 years ago

Pluto just takes the result of the expression you type, and displays it on your screen. The macros @which and @benchmark return an object, which is why you see something in your notebook.

In the same way, 8+8 returns the object 16 (Int), which becomes the 2-character string 16 on your notebook, or md"Heyo" returns a markdown object, which becomes the HTML code <p>Heyo</p> on your notebook.

The other macros you mentioned all return the object nothing (of type Nothing), which becomes the empty string on your notebook. These macros have a side effect, which is that they write to the terminal.

You can check this yourself: nothing === (@time 1 + 1) returns true.

Pluto does not do anything special with these macros (they are defined in Base after all), it just shows the returned object.

MikaelSlevinsky commented 4 years ago

I guess what I was trying to get at was that Jupyter notebooks output all macros to the cell output rather than the terminal

fonsp commented 4 years ago

Ah right! Jupyter does both, it shows the output value and also captures the terminal output stream. We have decided to keep things simple, and not capture the terminal output. (We think that rich output objects are the future, terminals are not.) Julia is generally really nice with this limitation, except for some APIs that were designed with the terminal in mind (beit the REPL or a terminal-capturing environment like Jupyter or Juno).

fonsp commented 4 years ago

Are there any APIs that you think are important and cannot be replaced with an object-returning alternative? (For example, which(funky, (Type1, Type2)) instead of @which)

fonsp commented 4 years ago

I was also thinking of showing a notification in Pluto when the user should check their terminal

MikaelSlevinsky commented 4 years ago

Are there any APIs that you think are important and cannot be replaced with an object-returning alternative? (For example, which(funky, (Type1, Type2)) instead of @which)

I'm just really impressed by the reactivity and my issues are regarding how to make the transition from Jupyter to Pluto less steep.

I was also thinking of showing a notification in Pluto when the user should check their terminal

Passing along INFO about precompiling seems like a good case.

SimonEnsemble commented 4 years ago

how can I get a macro e.g. @btime f(3.0) to print its output in the Pluto.jl notebook? this might be worth adding to the docs!

fonsp commented 4 years ago

You need to use @benchmark instead. It will take a while before #245 is done

drdozer commented 3 years ago

one option would be for a cell to have a 'show stdout' toggle