core

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 2 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package core is ontos/core (L0): the frozen value model.

Bytes = finite octet strings
Value = Atom(Bytes) | Tuple(Value*)

A value is finite, immutable, well-founded (a finite tree, never cyclic), uninterpreted, and compared by structural identity. This package defines what a value is and when two values are the same — nothing else. There is no byte encoding here (that is the codec package) and no interpretation of atoms or shapes. See docs/spec/ontos-core.md.

Common Value API (all three cores)

The Go, Rust, and TypeScript cores expose the same conceptual surface so a developer who learns one can predict the others. Every core provides, by its own naming convention:

  • Construct — NewAtom(bytes) / NewTuple(items...) (Rust Value::atom/tuple, TS atom/tuple).
  • Atom bytes + length — Atom.Bytes and Atom.Len.
  • Tuple children + arity + indexed access — Tuple.Items, Tuple.Len, and Tuple.At (matching Rust Tuple::at / TS Tuple.at).
  • Structural equality — Value.Equal and the package-level Equal (Rust PartialEq, TS equals).
  • Diagnostic string — Value.String (Rust Display, TS toString); this is not a canonical encoding.

Intentional per-language extras

Some members exist in only one core because they are idiomatic to that language and have no natural cross-core analogue; they are intentional, not accidental gaps. Go classifies a Value with an ordinary type switch or type assertion on the Value interface (e.g. a, ok := v.(Atom)), so it needs no is_atom/as_atom helpers; those exist only in Rust, where Value is a closed enum. The TS-only kind discriminant and toJSON/toHex serve JavaScript consumers that lack Rust enums and Go interfaces and want a stable JSON shape; Go has no such runtime JSON contract and so omits them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal(left, right Value) bool

Equal is the package-level structural identity relation.

Types

type Atom

type Atom struct {
	// contains filtered or unexported fields
}

Atom is an opaque finite byte string. The bytes have no built-in interpretation.

Construct atoms with Atom (which copies); the held bytes are not exposed by reference, so an Atom is immutable once built.

func NewAtom

func NewAtom(bytes []byte) Atom

NewAtom builds an Atom from a defensive copy of bytes. A nil slice yields the empty atom.

func (Atom) Bytes

func (a Atom) Bytes() []byte

Bytes returns a defensive copy of the atom's exact bytes.

func (Atom) Equal

func (a Atom) Equal(other Value) bool

Equal: an Atom equals another Atom with the exact same bytes; never a Tuple.

func (Atom) Len

func (a Atom) Len() int

Len is the atom's byte length.

func (Atom) String

func (a Atom) String() string

type Tuple

type Tuple struct {
	// contains filtered or unexported fields
}

Tuple is a finite ordered tuple of values. Arity, order, and multiplicity are part of the value's identity.

func NewTuple

func NewTuple(items ...Value) Tuple

NewTuple builds a Tuple from a defensive copy of items.

A nil child is not a value: the L0 set is generated only by Atom and Tuple (see docs/spec/ontos-core.md §1), so a nil Value interface cannot be a tuple child. Go has no closed sum type to enforce this statically, so the constructor is the gate — it panics on a nil child rather than admitting a malformed tuple that would later panic in Equal/Encode. Constructing a value from untrusted bytes goes through the codec's Decode, which never produces a nil child; this guard protects the in-process construction path.

func (Tuple) At

func (t Tuple) At(i int) Value

At returns child i, or nil if out of range.

func (Tuple) Equal

func (t Tuple) Equal(other Value) bool

Equal: a Tuple equals another Tuple of the same arity whose children are elementwise equal in order; never an Atom.

func (Tuple) Items

func (t Tuple) Items() []Value

Items returns a defensive copy of the tuple's ordered children.

func (Tuple) Len

func (t Tuple) Len() int

Len is the tuple's arity.

func (Tuple) String

func (t Tuple) String() string

type Value

type Value interface {
	// Equal reports structural identity with other.
	Equal(other Value) bool
	// String renders a diagnostic form (not a canonical encoding).
	String() string
	// contains filtered or unexported methods
}

Value is a foundational ontos value: either an Atom or a Tuple, and never anything else. The unexported marker method keeps the sum type closed: only Atom and Tuple in this package can implement it.

Jump to

Keyboard shortcuts

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