Skip to content

v0.4.0

Choose a tag to compare

@treytomes treytomes released this 24 Nov 14:30
· 35 commits to main since this release

Opens a .msnb file as a notebook whose cells share one MiniScript session, and lets a cell draw the diagram it built beside the text it printed.

Notebooks

A .msnb file opens the way an .ipynb does: a column of cells, each run on its own with Shift+Enter or the ▶ beside it, its output underneath. New MiniScript Notebook in the Command Palette opens one, and saving writes the .msnb beside the rest of the project. A new cell is MiniScript, and Markdown cells work as they do in any other notebook.

One session per notebook

The cells of a notebook share one interpreter process, so a name, a function or an import from one cell is there for the next:

x = 41          // first cell
print x + 1     // second cell prints 42

A cell of a single line also shows that line's value, the way the REPL echoes 1 + 1; a cell of several lines runs as one block, which has no value to echo, so write print for those. A runtime or compiler error stops that cell and is shown under it, and the session carries on with the values it already had.

Pictures

A cell can draw as well as print. notebook.mermaid(diagram) hands the lines mermaid.build(...) returns to VS Code's own Mermaid renderer, so the diagram is drawn under the cell — VS Code 1.121 or later, before which the fence shows as a code block. notebook.svg(mermaid.svg(facts, types, rules)) hands over an SVG document instead, which every version shows as a picture, since the project draws it itself. Both go through notebook.draw(mime, text), so anything with a type VS Code knows is drawn the same way, and what the cell prints is still its text output.

import "mermaid"

diagram = mermaid.build(facts, types, rules)
print diagram.join(char(10))   // the text, as always
notebook.mermaid(diagram)      // and the picture, under it

notebook.svg(mermaid.svg(facts, types, rules))   // the same diagram, drawn here

Imports and the working folder

A cell runs in the notebook's project folder, and import finds the project's modules there: MS_IMPORT_PATH defaults to the notebook's folder, <project>/src and the project folder, and an MS_IMPORT_PATH in the project's .env replaces that. A notebook has no entry script, but the session is given the notebook's own path as shellArgs before the REPL starts, and the notebook helpers are defined before the first cell runs. A loader that resolves a data file from the entry script has no script to go on, so name the file relative to the project folder — the micro-expert repository's examples/explore.msnb does exactly that with data/schema.kb, data/facts.kb and data/rules.kb.

A cell cannot read the keyboard: input would swallow the notebook's own lines, so a program that asks questions belongs in Run MiniScript File and its terminal.

Stopping, restarting and saving

The stop button kills the interpreter rather than the cell, since MiniScript cannot be interrupted part way; the next cell then starts a fresh session. Restart MiniScript Session, in the notebook toolbar, does the same deliberately. Closing the notebook ends its session, and only the cells are saved — outputs are not written to the file.

Installing

Requires VS Code 1.75 or newer. Attach the .vsix below with Extensions: Install from VSIX…, or from a terminal:

code --install-extension miniscript2-0.4.0.vsix