Session

it.grypho.scala.leonardo.cli.Session
See theSession companion object
final class Session

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
<expression>         evaluate, e.g.  f + 1  or  derive(f, x)
simplify <expr>      structural simplification, no numeric evaluation
expand <expr>        distribute products over sums
precision <n>        set decimal precision
exact on | off       exact rational arithmetic (default: off); see "help exact"
exact precision <n>  digits an irrational is approximated to (default: 30)
pretty on | off      multi-line, column-aligned matrix display (default: off)
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 <name>         remove a binding or definition
:load <file>         run a session script (file IO handled by the read loop)
:save <file>         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 Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def bodePoints(rest: String): Either[String, Sweep]

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: <expr> <var> <wMin> <wMax> [<n>]

Attributes

Returns

(omega, dB, degrees) triples, or the message explaining why there are none

def currentColorScheme: String

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

def execute(line: String): String

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

def load(text: String): String

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.

Value parameters

text

the script body (newline-separated commands)

Attributes

Returns

the concatenated non-empty output lines

def nyquistPoints(rest: String): Either[String, Samples]

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: <expr> <var> <wMin> <wMax> [<n>]

Attributes

Returns

(real, imaginary) pairs, or the message explaining why there are none

def samplePoints(rest: String): Either[String, Samples]

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 — <expr> <var> <lo> <hi> [<n>], 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: <expr> <var> <lo> <hi> [<n>]

Attributes

Returns

the sampling, or the message explaining why nothing could be sampled

def script: String

Current session state serialized as a replayable script — one command per line, precision 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, precision 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.

Attributes