Help us shape the future of Go! Take the 2026 Go Developer Survey

cells

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2026 License: BSD-3-Clause Imports: 10 Imported by: 0

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

func GoType(x any) string

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.

func GoValue

func GoValue(v rb.Value) any

GoValue is a Ruby value as a Go cell gets it; see the package documentation for the table.

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.

func (*Error) CellError

func (e *Error) CellError() string

CellError is the failure as a notebook shows it, without a Go stack.

func (*Error) Error

func (e *Error) Error() string

type Inspect

type Inspect string

Inspect is a Ruby value's inspect as a notebook shows it: plain text.

func (Inspect) Display

func (i Inspect) Display() map[string][]byte

Display shows the 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

func NewWriting(out, errOut io.Writer) *Session

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) Run

func (s *Session) Run(c Cell, show func(...any), note func(name, typ string))

Run runs a Ruby cell. show displays the value of its final expression; note(name, type) records the Go type each variable it assigns now has, in GoType's syntax, so the notebook can declare it. It panics with an *Error when the cell raises, which is how a worker fails a cell.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL