Programming in Nextjournal
Nextjournal offers an intuitive WYSIWYG interface for creating and publishing notebooks. The features covered in this article will make working with code and environments more convenient through the use of several powerful features.
Runtimes
A Nextjournal environment is a filesystem snapshot of the runtime, stored as a Docker image. It includes everything necessary to run valid code in its associated code cells.
A runtime is the execution of the environment, running within a Docker container. When running, a user can execute programs written in its associated code cells.
Here an active Python runner denoted by the green dot and a R runner, which has timed out, is denoted by the gray dot.
Error Messages
Error messages appear inline. Large messages can be collapsed by clicking show less.
address = {street: "1 Lincoln Drive", zip: } address["zip"]
Short error messages remain succinct.
ls /liszt 2> /dev/null
While long error messages, like Clojure's enormous stack traces, default to a collapsed state. They can be expanded by clicking show more.
{:x :y 1}
Autocomplete
Use the ↹ Tab key to hint packages, variables, methods, and functions.
This works in Python, R, Bash, Julia, Clojure, and ClojureScript.
It's best to use this while your runner is still running. Some language features may still autocomplete in an inactive runner. For example, R primitives like list
are always available, but base functions like print
are not:
get("list", envir = baseenv())
get("print", envir = baseenv())
Base Python classes do not need an active runner but functions do. Furthermore, imported packages will need an active runner to autocomplete in all languages.
For best results keep your runners active by executing code early and often!
Documentation
Documentation can called from the code cell or inline through a Nextjournal shortcut, ⇪Shift ↹ Tab.
Inline
Using the Nextjournal shortcut, ⇪Shift ↹ Tab:
Inline documentation works for Python, Julia, and R.
Code Cell
help(abs)
Imported and Required Packages
The documentation shortcut, ⇪Shift ↹ Tab, works the same for the NamedTemporaryFile()
function from the tempfile
module as it does anywhere else in Python.
import tempfile help(tempfile.NamedTemporaryFile)