R9 — Your session

Goal: keep work between visits, hand it to someone else, and set the REPL up the way you like it.

Close the browser tab and everything below is gone — the REPL keeps nothing by itself. This lesson is about the three ways to stop that mattering.

What a session actually is

> k := 5
k := 5.0
> damped := exp(-k*t) * sin(t)
damped := (exp((-1.0 * (k * t))) * sin(t))
> env
precision = 5
k := 5.0
damped := (exp((-1.0 * (k * t))) * sin(t))

run this session

Everything you have set — bindings, definitions, settings — can be written back out as the commands that would recreate it. That is the whole persistence mechanism.

A session is the environment your next command runs in, not a record of how you got there. What it leaves out matters as much as what it keeps: the transcript — every result you printed, every line you typed — and any figure you drew are not part of it.

Why a script rather than a snapshot?

Because a script is something you can read, edit, diff and send. A saved session is plain text in the same language you have been typing, and loading it runs those commands, which rebuild the environment: the same bindings, definitions and settings. It is not a replay of your work — the saved script holds only the commands that set something, never the ones that printed or drew. One consequence is worth noticing: saving, loading and sharing are not three features, they are one idea used three ways.

(At the terminal, :load also runs a script you wrote yourself, and that can contain any command you could type — R10. In the browser, storage and links only ever hold what :save and Share wrote, so there loading restores an environment and nothing else.)

It is also why the order inside a saved file matters — settings are written before bindings, so that a script re-enables exact before it parses the values that need it (R8).

Saving and loading

At the terminal prompt:

> :save work.leo
saved to work.leo
> :load work.leo

In the browser the same two commands work, but there is no file system, so the name is a key in the browser’s own storage — :save work, then :load work, in the same browser on the same site. The spelling is deliberately identical: two builds of one REPL should not speak two command languages.

The browser REPL’s Share button encodes your whole session into the address — specifically into the part after #, which browsers never send to a server, so your work stays on your machine. Anyone opening that link arrives with your bindings and settings already in place.

It carries your environment, not what you saw. The transcript stays behind, and so does any figure: plot draws from the environment but leaves nothing in it, so the person opening the link sees no figure until they draw it again.

It is the fastest way to ask someone a question about a calculation: send the link, not a screenshot of it — and if the question is about a figure, send the plot line with it.

Settings worth knowing

Each reports its state when typed bare, and each is saved with the session:

> pretty
pretty = off
> latex
latex = off
> names
names = off
> exact
exact = off, working precision = 30
> logic
logic minmax
logic symmetric = off

run this session

You have met pretty (R6) and exact (R8). Two more are worth a moment.

names on — the typo catcher

R2 showed that an unknown name is a perfectly good variable, so a misspelling cannot be an error. names on makes it visible instead:

> names on
names = on
> velocty + 1
(velocty + 1.0)
  note: new name: velocty

run this session

The note announces every newly-seen free variable — so a typo shows up as a name you did not intend to create. It is off by default because in a computer algebra system a new free variable is the normal case, not a suspicious one; turn it on while you are working with concrete quantities, off when you are doing algebra:

> names off
names = off

run this session

latex on — a second channel

> latex on
latex = on
> (a + b)/(c + d)
((a + b) / (c + d))
> latex off
latex = off

run this session

The text is identical either way, which is the point — and it is why this page shows no difference. The typeset formula travels on a second channel that only a front end able to render it picks up. In the browser you would see the fraction properly set beside the line above, never instead of it: the text is the canonical form you would have to retype, so it is the one thing that may not be hidden.

pretty and latex exclude each other — turning one on turns the other off — because both are ways of laying a matrix out, and doing both at once would show the same thing twice.

Starting clean

> unset damped
damped unset
> unset k
k unset
> env
precision = 5

run this session

Try it yourself

You are about to work with measured quantities and want typos caught. Turn on the diagnostic, then evaluate tempreature * 2 and see what it tells you.

Answers ```text > names on names = on > tempreature * 2 (tempreature * 2.0) note: new name: tempreature > names off names = off ``` *[run this session](https://lycogrypho.github.io/Leonardo/app/#s=precision%205%0Acolors%20dark%0Apretty%20off%0Alatex%20off%0Anames%20off%0Alogic%20minmax%0Alogic%20symmetric%20off%0Aexact%20precision%2030%0Aexact%20off)* Without the setting that line is a perfectly ordinary expression in a variable you never meant to create — and it would stay ordinary all the way to a wrong answer.

What you learned

  • A session is its environment written as a script — settings, bindings, definitions — which is why :save, :load and Share are one idea. The transcript and figures are not in it.
  • The browser uses its own storage instead of files; the commands are spelled the same.
  • A share link carries the session in the URL fragment, which never leaves your machine; a figure has to be drawn again.
  • names on catches the typo-becomes-variable trap; latex on adds typeset output beside the text, never instead of it.
  • Settings are saved with the session, and written before the bindings that depend on them.

Previous: R8 — Exact arithmetic · Next: R10 — The terminal REPL · All lessons


This site uses Just the Docs, a documentation theme for Jekyll.