Interactive command-line session over the Leonardo library.
Session state lives outside the library's Environment because the two kinds of assignment differ: a constant right-hand side becomes a numeric binding (a _Value the Environment can hold), while a right-hand side with free variables becomes a named definition (a symbolic _Expression, which the Environment deliberately cannot hold). Definitions are late-bound: they are substituted into input at use time, so redefining f also changes any g defined in terms of f.
Assignment uses := (CAS convention): bare = always parses as an _Equation, so x = 2*x + 1 is a relation to evaluate, never a binding. Session scripts (:save) emit := and old =-style scripts are not accepted.
Commands:
x := 3.001 bind a value (constant right-hand side)
f := sin(x) + x define a function (right-hand side with free variables)
h := lhs = rhs bind a named equation (can be passed to solve(h, x))
g := consolidate(e) freeze the simplified+evaluated result of e into g (not late-bound)
lhs = rhs equation: true/false when concrete; solvable via solve()
lhs == rhs equality check: evaluates to bool but not solvable
evaluate, e.g. f + 1 or derive(f, x)
simplify structural simplification, no numeric evaluation
expand distribute products over sums
precision set decimal precision
exact on | off exact rational arithmetic (default: off); see "help exact"
exact precision digits an irrational is approximated to (default: 30, max 1000)
pretty on | off multi-line, column-aligned matrix display (default: off)
latex on | off also emit each result as LaTeX, for a front end that can
typeset it (default: off); see [[Session.lastLatex]]
logic symmetric on|off spell truth values as -1 / 0 / 1 (default: off)
logic minmax|product|lukasiewicz fuzzy t-norm family (default: minmax)
env list precision, bindings, and definitions
unset remove a binding or definition
:load run a session script (file IO handled by the read loop)
:save write current state to a replayable script (read loop)
help this summary
quit | exit leave (handled by the read loop)
Attributes
- Companion
- object
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
Members list
Value members
Concrete methods
The frequency sweep behind the browser's bode command (issue F_0004).
The frequency sweep behind the browser's bode command (issue F_0004).
The same arguments as samples, read as a frequency band rather than a range: the grid is geometric and the phase is unwrapped, neither of which sample does. A Bode diagram cannot be drawn from a linear grid — it would put almost every point in the last decade — nor from a wrapped phase, which jumps a full turn at the arctangent's branch cut.
Value parameters
- rest
-
the command's arguments:
<var> []
Attributes
- Returns
-
(omega, dB, degrees)triples, or the message explaining why there are none
Returns the name of the active colour scheme ("dark", "light", or "none").
Returns the name of the active colour scheme ("dark", "light", or "none").
Attributes
Executes one line of input and returns the display string.
Executes one line of input and returns the display string.
Dispatches to the appropriate command handler or falls through to expression evaluation. Returns an empty string for blank input.
Value parameters
- line
-
the raw input line (not yet trimmed)
Attributes
- Returns
-
the result to print, or
""for silent commands
A figure of lines as an SVG image, for a page rendered ahead of time (F_0238).
A figure of lines as an SVG image, for a page rendered ahead of time (F_0238).
Each line is a drawing command in the command language: plot, points, curve, arrows, polygon, hist, bode, nyquist or rlocus, and a line may hold several separated by ;. Every command in the call is one layer on shared axes, the axes locked to one scale when any layer is geometry in the plane; a Bode diagram has two panels and is drawn alone. The data is this session's, read exactly as the browser's figures read it, so a figure cannot disagree with a transcript, and the same text typed in the browser REPL draws the same figure there.
The three primitives only a figure needs: arrows M draws an arrow from the origin to each column of the 2×n matrix M; polygon M fills the polygon whose vertices are its columns; curve E t lo hi [n] traces the 2×1 column E as t runs over [lo, hi], so curve A*[[cos(t)], [sin(t)]] t 0 6.2832 ; arrows A is the unit circle's image under A with A's columns. The image uses the reference palette on a light surface, carries a legend for two or more layers, and embeds no font.
Value parameters
- lines
-
the drawing commands
Attributes
- Returns
-
the `` document, or the message explaining why nothing could be drawn
The binned sample behind the browser's hist command (F_0135): [], the sample binned over its own range in k equal bins, Sturges' ⌈log₂ n⌉ + 1 when k is not given.
The binned sample behind the browser's hist command (F_0135): [], the sample binned over its own range in k equal bins, Sturges' ⌈log₂ n⌉ + 1 when k is not given.
The trailing count is read before the expression, since x 10 would otherwise parse as the product x·10 — but only when what precedes it is a sample (F_0143): y * 2 split into the sample y * and failed with a parse error that never said the 2 had been taken, so when the text before the integer is not a sample the whole text is read, with Sturges' bins. A count that cannot be read is refused, never replaced by Sturges' rule, and a cell that is not a real number refuses the sample rather than being dropped from it. A constant sample is given the unit range around its value, the one bin it fills. The counts come from statistics.binCounts, so the figure and bincounts(x, lo, hi, k) at the prompt cannot disagree; the data is returned rather than printed, the samplePoints split, so a plotter never re-reads rounded text.
Value parameters
- rest
-
the command's arguments:
[]
Attributes
- Returns
-
the bin edges and counts, or the message explaining why there are none
The LaTeX of the last expression execute produced, or None.
The LaTeX of the last expression execute produced, or None.
Always None while latex off, and always None after a command that produced no expression — a help listing, an error, a bare setting. This is a second channel, not a second format: execute returns exactly the same text either way, so a front end that cannot typeset is unaffected and one that can chooses per result.
Attributes
The expression the last line execute ran answered with, or None (F_0126).
The expression the last line execute ran answered with, or None (F_0126).
Filled by the same commands as lastLatex — bare evaluation, simplify, expand — through the same wrapper, so the text, the LaTeX and the value cannot drift; unlike the LaTeX it survives a note, since the value is still the answer. The MCP server renders it as Scala source.
Attributes
- Returns
-
the result, or
Noneafter a command that produced no expression
Execute a whole script body (e.g. the contents of a :load file), returning the newline-joined non-empty outputs of its commands. Blank lines and # comments are skipped. IO-free — the caller supplies the text, so this is unit-testable; the REPL loop is the only place that actually reads the file.
Execute a whole script body (e.g. the contents of a :load file), returning the newline-joined non-empty outputs of its commands. Blank lines and # comments are skipped. IO-free — the caller supplies the text, so this is unit-testable; the REPL loop is the only place that actually reads the file.
The LaTeX channel is cleared afterwards (issue F_0020): every line runs through execute, so the channel would be left holding the last line's formula — and a front end that shows a formula in place of the text would then typeset that one line and drop everything else the script produced. A script's output is a transcript, not a result.
Value parameters
- text
-
the script body (newline-separated commands)
Attributes
- Returns
-
the concatenated non-empty output lines
The Nyquist sweep — bodePoints's grid, in rectangular coordinates (issue F_0004).
The Nyquist sweep — bodePoints's grid, in rectangular coordinates (issue F_0004).
Returns Session.Samples rather than a type of its own because a Nyquist diagram is a set of plane coordinates, which is exactly what the points plot already draws — and draws with the axes locked to the same scale, without which the picture is wrong.
Value parameters
- rest
-
the command's arguments:
<var> []
Attributes
- Returns
-
(real, imaginary)pairs, or the message explaining why there are none
How many samples the sweeping commands will attempt for rest (issue F_0044).
How many samples the sweeping commands will attempt for rest (issue F_0044).
Additive rather than a field on Session.Samples, which is what it looks like it should be: that record is public API of a published module, so widening it would break binary compatibility and cost a mimaBinaryIssueFilters entry — against a list whose emptiness is worth keeping, and for a message. Reading the count back through the same sweepArgs parser costs one cheap re-parse and leaves the argument syntax with a single definition, which is the property that matters.
Value parameters
- rest
-
the command's arguments, exactly as passed to samplePoints
Attributes
- Returns
-
the requested count, or
Nonewhen the arguments do not parse
The root locus behind the browser's rlocus command (F_0140): samples' argument syntax through the shared sweepArgs, read as a band of gains — geometric when it starts above zero — answering continuous branches with the open-loop poles and zeros for markers.
The root locus behind the browser's rlocus command (F_0140): samples' argument syntax through the shared sweepArgs, read as a band of gains — geometric when it starts above zero — answering continuous branches with the open-loop poles and zeros for markers.
Value parameters
- rest
-
the command's arguments:
<var> []
Attributes
- Returns
-
the locus, or the message explaining why there is none
Samples an expression over a range, returning the POINTS rather than a rendering of them.
Samples an expression over a range, returning the POINTS rather than a rendering of them.
This is the samples command's argument syntax — <var> [], exactly the text that follows the keyword — resolved to data. doSamples renders it as the tab-separated table the terminal REPL prints, and the browser front end (F_0003 phase 3) hands the same vector to a plotting library.
The split is what keeps the two honest. A plotter cannot re-read the printed table: that text is rounded to the session's display precision, so parsing it back would plot a deliberately lossy copy of a full-precision computation. Having one method own the argument parsing, the bounds validation and the sampling — with printing and drawing as two renderings of its result — is the same arrangement logic.simplifyLogic uses for its injected leaf pass, and it means a plot and a printed table can never disagree about what was sampled.
Value parameters
- rest
-
the command's arguments:
<var> []
Attributes
- Returns
-
the sampling, or the message explaining why nothing could be sampled
Current session state serialized as a replayable script — one command per line, settings first, then bindings and definitions in name order. Feeding this back through load (or line by line through execute) reconstructs the session. Pure: this is what the REPL writes to a :save file.
Current session state serialized as a replayable script — one command per line, settings first, then bindings and definitions in name order. Feeding this back through load (or line by line through execute) reconstructs the session. Pure: this is what the REPL writes to a :save file.
Each value is written under the mode it must be parsed in (F_0090). Exact mode is a parse-time decision, so one exact line before every value re-parsed them all in the session's current mode: in exact mode a saved Double came back an exact rational, and with it off a saved exact rational came back a Double. The entries are therefore written in two groups — those with no exact value under exact off, those with one under exact on, an empty group omitted — and the session's own mode last, when the groups did not end in it. A session with no exact values writes exactly the script it always did. The one case left lossy is a single definition holding values of both tiers (only consolidate in exact mode over a Double binding builds one): it can be parsed in one mode only, and is written under exact on.
Attributes
The session's settings as (command, argument) pairs — see settingPairs.
The session's settings as (command, argument) pairs — see settingPairs.
A List, not a Map: the order is the one a script replays in, and a control panel that lays the settings out in the session's own order needs no order of its own.