Documentation
¶
Overview ¶
Package cells runs the Ruby cells of a notebook: one Ruby interpreter per session, with the go-scikit modules registered, whose top-level locals persist from cell to cell, and the exchange of variables with the Go cells of the same notebook.
It is what a go-notebook worker links when a notebook has Ruby cells; the generated program calls Run once per Ruby cell. It knows nothing of the notebook runtime: the cell's display and notes reach it through funcs.
Variables across languages ¶
A Go variable a Ruby cell reads is set as a Ruby local of the same name before the cell runs, converted as rbgo converts Go values (see rb.Value): a []float64 becomes an Array of Floats, a map a Hash, an *ndarray.Array the NDArray itself, any other value an opaque object that comes back as itself. A Go variable whose name starts with an upper-case letter becomes a Ruby constant.
A Ruby local a cell assigns is handed back to Go after the cell runs, into a Go variable of the type its value has (GoValue): nil, true/false, Integer (int64, or *big.Int when large), Float (float64), String (string), Symbol (ruby.Symbol), Complex (complex128), Rational (*big.Rat), NDArray (*ndarray.Array, the same array), an Array whose elements are all Floats, all Integers, all Strings or all booleans ([]float64, []int64, []string, []bool; otherwise []any), a Hash with String keys (map[string]any; with Symbol keys map[ruby.Symbol]any; otherwise map[any]any), an object of a go-scikit class (the Go value it wraps: *plot.Figure, stats.TTestResult, …), and any other Ruby object as a ruby.Value.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GoType ¶
GoType names the Go type of a converted value for a generated program: built-in types as Go writes them, and a named type of another package as {import/path}.Name, which the generator turns into an import and a qualified name. A type it cannot name — nil, an unexported or generic type, a func — is any.
Types ¶
type Cell ¶
type Cell struct {
Source string
File string // the notebook
Line int // where Source starts in it
// Display shows the value of the cell's final expression.
Display bool
// In are the variables the cell reads, Out those it assigns.
In, Out []Var
}
Cell is one Ruby cell to run.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error is a Ruby cell's failure: the exception, at its line in the notebook, with the backtrace frames in the notebook.
type Inspect ¶
type Inspect string
Inspect is a Ruby value's inspect as a notebook shows it: plain text.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is the Ruby side of one notebook worker.
func New ¶
func New() *Session
New starts an interpreter with the go-scikit modules, writing to the process's standard output and error.
func NewWriting ¶
NewWriting is New writing what Ruby prints to out, and its $stderr and warnings to errOut: a host that captures a cell's output itself.
func (*Session) Complete ¶ added in v0.2.0
Complete returns the completions of target, the word before the cursor, in the session's state — the candidates IRB's default completor (RegexpCompletor) gives: the methods of a literal's class after a dot, of a local, global or instance variable or a constant path's value after a dot or ::, the constants of a module after ::, the global variables after $, and otherwise the locals, the methods and instance variables of main, the constants and the keywords. Each candidate is the whole word, receiver included ("x.size"), sorted for a bare name.
Unlike IRB, it evaluates nothing the word does not name: a receiver is a variable or a constant path, never an expression, so pressing Tab never calls a method of the input. A variable's own #methods is called, as IRB does.
func (*Session) Eval ¶ added in v0.2.0
func (s *Session) Eval(src, file string, line int) (inspect string, display map[string][]byte, err error)
Eval evaluates src, one input of an interactive session that starts at line of file, and sets the local `_` to its value, as irb does. It returns the value's inspect and, when the value shows itself (a Plot figure), its MIME bundle — an NDArray shows its inspect only, as in a cell.
An exception returns an *Error whose text is the message and class, then the backtrace frames in file (twelve at most); its Class says which exception it was (SystemExit for exit). `_` is left as it was.
type Var ¶
type Var struct {
Name string
Ptr any
// IfAbsent sets the Ruby local only when the interpreter does not hold
// it already: a Ruby cell's variable, which the interpreter keeps between
// cells but which a new worker gets back from its Go holder.
IfAbsent bool
}
Var is a notebook variable at the boundary: its name and a pointer to the Go variable that holds it.