vm

package
v1.12.1 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TraceVarNS   = "core"
	TraceVarName = "*lg-trace*"
)

TraceVarNS and TraceVarName identify the tracing control var, defined in the core namespace as `(def ^:dynamic *lg-trace* false)`. Both are matched so a user-namespace var that happens to be named *lg-trace* cannot hijack the gate.

View Source
const (
	OP_NOOP int32 = iota // do nothing

	OP_LOAD_CONST // load constant LDC (index int32)
	OP_LOAD_ARG   // load argument LDA (index int32)

	OP_INVOKE // invoke function
	OP_RETURN // return from function

	OP_BRANCH_TRUE  // branch if truthy BRANCH_TRUE (offset int32)
	OP_BRANCH_FALSE // branch if falsy BRF (offset int32)
	OP_JUMP         // jump by offset JMP (offset int32)

	OP_POP     // pop value from the stack and discard it
	OP_POP_N   // save top and pop n elements from the stack POP_N (n int32)
	OP_DUP_NTH // duplicate nth value from the stack OPN (n int32)

	OP_SET_VAR  // set var
	OP_LOAD_VAR // push var root

	OP_MAKE_CLOSURE    // make a closure out of fn
	OP_LOAD_CLOSEDOVER // load closed over LDK (index int32)
	OP_PUSH_CLOSEDOVER // push closed over value to a closure

	OP_RECUR    // loop recurse RECUR (offset int32, argc int32)
	OP_RECUR_FN // function recurse REF (argc int32)

	OP_MAKE_MULTI_ARITY // make multi-arity function (n int32)
	OP_TAIL_CALL        // like OP_INVOKE but re-uses the frame

	OP_TRY_PUSH // push exception handler (catchOffset int32, finallyOffset int32)
	OP_TRY_POP  // pop exception handler (normal completion)
	OP_THROW    // throw top-of-stack value

	// Specialized arithmetic/comparison opcodes (binary, stack: [a b] -> [result])
	// These inline the common int64 fast path and fall back to generic NumXxx for other types.
	OP_ADD // + (2 args)
	OP_SUB // - (2 args)
	OP_MUL // * (2 args)
	OP_BIT_AND
	OP_BIT_OR
	OP_BIT_XOR
	OP_BIT_AND_NOT
	OP_BIT_SHIFT_LEFT
	OP_BIT_SHIFT_RIGHT
	OP_UNSIGNED_BIT_SHIFT_RIGHT
	OP_LT  // < (2 args)
	OP_LTE // <= (2 args)
	OP_GT  // > (2 args)
	OP_GTE // >= (2 args)
	OP_EQ  // = (2 args)
	OP_INC // inc (1 arg)
	OP_DEC // dec (1 arg)
	OP_BIT_NOT
	OP_QUOT // quot — integer quotient, truncated toward zero (2 args)
	OP_DIV  // / — true division; int/int yields a Ratio (or Int when exact), any float yields Float (2 args)

	OP_FINALLY_END // end of a finally block (finallyOffset int32, negative): rethrow the pending error after an abnormal entry

	OP_COUNT // sentinel — keep last; must equal len(opcodeNames) (enforced at init)
)

Opcodes

View Source
const BigDecimalPrecConst = bigDecimalPrec

Variables

View Source
var (
	ClassThrowable            = newExceptionClass("java.lang.Throwable", nil)
	ClassError                = newExceptionClass("java.lang.Error", ClassThrowable)
	ClassAssertionError       = newExceptionClass("java.lang.AssertionError", ClassError)
	ClassException            = newExceptionClass("java.lang.Exception", ClassThrowable)
	ClassIOException          = newExceptionClass("java.io.IOException", ClassException)
	ClassInterruptedException = newExceptionClass("java.lang.InterruptedException", ClassException)
	ClassRuntimeException     = newExceptionClass("java.lang.RuntimeException", ClassException)
	ClassArithmeticException  = newExceptionClass("java.lang.ArithmeticException", ClassRuntimeException)
	ClassClassCastException   = newExceptionClass("java.lang.ClassCastException", ClassRuntimeException)
	ClassIllegalArgument      = newExceptionClass("java.lang.IllegalArgumentException", ClassRuntimeException)
	ClassNumberFormat         = newExceptionClass("java.lang.NumberFormatException", ClassIllegalArgument)
	ClassIllegalState         = newExceptionClass("java.lang.IllegalStateException", ClassRuntimeException)
	ClassIndexOutOfBounds     = newExceptionClass("java.lang.IndexOutOfBoundsException", ClassRuntimeException)
	ClassNullPointer          = newExceptionClass("java.lang.NullPointerException", ClassRuntimeException)
	ClassUnsupportedOperation = newExceptionClass("java.lang.UnsupportedOperationException", ClassRuntimeException)
)
View Source
var (
	IFnProtocol *Protocol
	IFnInvoke   Fn
	// IDerefProtocol / IDerefDeref wire "derefable values": any value whose type
	// satisfies IDeref can be used with @ / deref, dispatched to its -deref
	// method. Set once by the runtime after core defines the IDeref protocol.
	IDerefProtocol *Protocol
	IDerefDeref    Fn
)

IFnProtocol and IFnInvoke wire up "invokable values": any value whose type satisfies IFnProtocol can be called like a function, with the call dispatched to its -invoke method (the IFnInvoke protocol fn). They are set once by the runtime after core defines the IFn protocol; until then invoking a non-Fn value is a plain type error, as before.

View Source
var AnyType *theAnyType = &theAnyType{}
View Source
var ArrayVectorType *theArrayVectorType = &theArrayVectorType{}

ArrayVectorType is the type of ArrayVectors

View Source
var AtomType *theAtomType = &theAtomType{}
View Source
var BigDecimalType *theBigDecimalType = &theBigDecimalType{}
View Source
var BigIntType *theBigIntType = &theBigIntType{}
View Source
var BooleanType *theBooleanType = &theBooleanType{zero: FALSE}

BooleanType is the type of Boolean

View Source
var (
	BoxedTypes map[string]*aBoxedType = map[string]*aBoxedType{}
)

BoxedType is the type of NilValues. Guarded by boxedTypesMu: boxing values from multiple goroutines (e.g. parallel lowering) otherwise races on this shared map, which is a runtime panic for concurrent writes, not just a detector warning.

View Source
var ChanType *theChanType = &theChanType{}

ChanType is the type of Chan

View Source
var CharType *theCharType = &theCharType{zero: utf8.RuneError}

CharType is the type of CharValues

View Source
var ComparableFallback func(a, b Value) (int, bool, error)

ComparableFallback, when set, is consulted by DefaultCompare for values it cannot order natively. It dispatches on a's type only (mirroring Clojure's compare, which calls a.compareTo(b)) and returns (result, handled, err): handled is false when a's type has no Comparable implementation, in which case DefaultCompare reports its usual error. The runtime (package rt) wires this at init to route through the Comparable protocol; it lives here as a hook to avoid a vm->rt import cycle. Because compare, sort, and sorted-set all funnel through DefaultCompare, registering once makes all three respect Comparable — matching Clojure, where sort/sorted-set use compare.

View Source
var DelayType *theDelayType = &theDelayType{}
View Source
var EmptyPersistentMap = &PersistentMap{count: 0, root: nil}

EmptyPersistentMap is the canonical empty persistent map.

View Source
var EmptyPersistentSet = &PersistentSet{impl: EmptyPersistentMap}

EmptyPersistentSet is the canonical empty set.

View Source
var EmptySortedMap = &SortedMap{cmp: DefaultCompare}
View Source
var EmptySortedSet = &SortedSet{impl: EmptySortedMap}
View Source
var ExInfoType *theExInfoType = &theExInfoType{}
View Source
var ExceptionClasses []*ExceptionClass

ExceptionClasses lists every canonical class in registration order so pkg/rt can Def names and constructors by iteration.

View Source
var FloatType *theFloatType = &theFloatType{zero: 0}

FloatType is the type of Float values

View Source
var FormSource = &formSourceMap{m: map[any]*SourceInfo{}}

FormSource maps form values to their source locations. Used by the compiler to attach source info to bytecode. Only pointer-based types (like *List) can be tracked; slice/value types are not hashable and are silently ignored.

View Source
var FuncType *theFuncType = &theFuncType{}
View Source
var Goroutines = newRootScope()

Goroutines is the process-wide root scope. Every VM spawn goes through a scope; blocking ops consult its Context for cancellation.

View Source
var InstantType *theInstantType = &theInstantType{}

InstantType is the type of Instant values.

View Source
var IntType *theIntType = &theIntType{zero: 0}

IntType is the type of IntValues

View Source
var IterateType *theIterateType = &theIterateType{zero: nil}

IterateType is the type of IterateValues

View Source
var KeywordType *theKeywordType = &theKeywordType{zero: "????BADKeyword????"}

KeywordType is the type of KeywordValues

View Source
var ListType *theListType = &theListType{}

ListType is the type of Lists

View Source
var MapType *theMapType = &theMapType{}

ArrayVectorType is the type of ArrayVectors

View Source
var MultiFnType *theMultiFnType = &theMultiFnType{}
View Source
var NamespaceType *theNamespaceType = &theNamespaceType{}
View Source
var NativeFnType *theNativeFnType = &theNativeFnType{}
View Source
var NilType *theNilType = &theNilType{zero: nil}

NilType is the type of NilValues

View Source
var PersistentMapType *thePersistentMapType = &thePersistentMapType{}

PersistentMapType is the type of PersistentMap values.

View Source
var PersistentVectorType *thePersistentVectorType = &thePersistentVectorType{}

PersistentVectorType is the type of PersistentVectors

View Source
var ProfilingEnabled atomic.Bool

ProfilingEnabled gates the per-opcode increments in Frame.Run. Read on every opcode dispatch when true; a single atomic Load.

View Source
var PromiseType *thePromiseType = &thePromiseType{}
View Source
var ProtocolType *theProtocolType = &theProtocolType{}
View Source
var QueueType *theQueueType = &theQueueType{}

QueueType is the type of PersistentQueues.

View Source
var RangeType *theRangeType = &theRangeType{}

RangeType is the type of Lists

View Source
var RatioType *theRatioType = &theRatioType{}
View Source
var ReducedType *theReducedType = &theReducedType{}
View Source
var RegexType *theRegexType = &theRegexType{}

RegexType is the type of RegexValues

View Source
var RepeatType *theRepeatType = &theRepeatType{zero: nil}

RepeatType is the type of RepeatValues

View Source
var RootExecContext = &ExecContext{bindings: globalBindingStack}

RootExecContext is the always-available default context. Frames with no more specific context resolve against it.

View Source
var ScopeType *theScopeType = &theScopeType{}

ScopeType is the Value type of a Scope handle.

View Source
var SequenceType *theSequenceType = &theSequenceType{}

SequenceType is the type of Sequences

View Source
var SetType *theSetType = &theSetType{}

ArrayVectorType is the type of ArrayVectors

View Source
var SortedMapType *theSortedMapType = &theSortedMapType{}
View Source
var SortedSetType *theSortedSetType = &theSortedSetType{}
View Source
var SourceRegistry = &sourceRegistry{sources: map[string]string{}}

SourceRegistry stores source text for error display. Maps file names to their full source text.

View Source
var StringType *theStringType = &theStringType{zero: ""}

StringType is the type of StringValues

View Source
var SymbolType *theSymbolType = &theSymbolType{zero: "????BADSYMBOL????"}

SymbolType is the type of Symbol values

View Source
var TraceArmed atomic.Bool

TraceArmed is the coarse gate read once per frame entry in Frame.Run. It is flipped true the first time *lg-trace* is bound or set to a truthy value (see pushBinding and OP_SET_VAR). Once armed it stays armed for the process lifetime; a frame only actually traces when the precise per-frame Deref of TraceVar is also truthy, so disarming is unnecessary (an unbound/false *lg-trace* simply produces no trace).

View Source
var TraceVar atomic.Pointer[Var]

TraceVar is the interned core `*lg-trace*` var, letting the VM — which cannot import pkg/rt — resolve the var's current dynamic value against a frame's ExecContext. It self-wires the first time *lg-trace* is bound or set truthy (armTraceIfTruthy), so no rt-side core-load hook is needed; nil until then, in which case tracing is inert.

View Source
var TransientMapType *theTransientMapType = &theTransientMapType{}
View Source
var TransientSetType *theTransientSetType = &theTransientSetType{}
View Source
var TransientVectorType *theTransientVectorType = &theTransientVectorType{}
View Source
var TypeType *theTypeType = &theTypeType{}
View Source
var TypedArrayType *theTypedArrayType = &theTypedArrayType{}

TypedArrayType is the singleton type for all typed arrays.

View Source
var UUIDType *theUUIDType = &theUUIDType{}

UUIDType is the type of UUID values

View Source
var ValueEquals func(a, b Value) bool

ValueEquals performs deep structural equality comparison. Used by the = operator and OP_EQ opcode.

View Source
var VoidType *theVoidType = &theVoidType{zero: &Void{}}

VoidType is the type of VoidValues

View Source
var VolatileType *theVolatileType = &theVolatileType{}

Functions

func AddBaselineNamespace added in v1.12.0

func AddBaselineNamespace(ns *Namespace)

AddBaselineNamespace registers ns as an auto-refer'd resolution baseline.

func AllocAttrEnabled added in v1.12.0

func AllocAttrEnabled() bool

AllocAttrEnabled reports whether .lg allocation attribution is on. Used by rt to serialize pmapv workers so the shadow stack is coherent.

func CloseScoped added in v1.9.0

func CloseScoped(c *Scope, timeout time.Duration)

CloseScoped tears a with-scope child down: cancel the subtree, drain up to timeout (warn on a straggler), restore the caller's previous current scope via the restore closure OpenChildEC installed, and unparent the child so it is not retained.

func ComputeSignatureForNames added in v1.12.0

func ComputeSignatureForNames(names []string) (count int, hash uint64)

ComputeSignatureForNames computes an opcode-set signature for a given list of opcode names. Used by the bytecode migration system to compute signatures for older opcode sets.

func DefaultCompare added in v1.5.0

func DefaultCompare(a, b Value) (int, error)

DefaultCompare is the default comparator used by sorted collections. It handles nil, numbers, strings, keywords, symbols, booleans, and chars.

func DumpAllocAttr added in v1.12.0

func DumpAllocAttr(w io.Writer)

DumpAllocAttr writes the attribution report: per-kind totals, then the top call-stack keys by bytes.

func FormatError

func FormatError(err error) string

FormatError produces a user-friendly error display with source snippets, inspired by Rust/Elm-style error reporting.

func GuardedRootsIntact added in v1.12.0

func GuardedRootsIntact() bool

GuardedRootsIntact reports that no guarded native-primitive var root is currently overridden. One atomic load — cheap enough for emitted per-call guards in the lowered tree.

func HashValue added in v1.3.1

func HashValue(v Value) uint32

HashValue computes a 32-bit hash for any Value type (exported for builtins).

func IsBigDecimal added in v1.5.0

func IsBigDecimal(v Value) bool

IsBigDecimal returns true if v is a *BigDecimal.

func IsBigInt

func IsBigInt(v Value) bool

IsBigInt returns true if v is a *BigInt.

func IsNumber

func IsNumber(v Value) bool

IsNumber returns true if the value is Int, Float, or BigInt.

func IsRatio added in v1.5.0

func IsRatio(v Value) bool

IsRatio returns true if v is a *Ratio.

func IsReduced

func IsReduced(v Value) bool

func IsTruthy

func IsTruthy(v Value) bool

func Iter added in v1.8.0

func Iter(v Value) iter.Seq[Value]

Iter returns a Go-1.23+ iter.Seq[Value] over any let-go sequence value. Yields nothing if v is nil/NIL or isn't a sequence.

Preserves laziness: the underlying LazySeq thunks are realized one step at a time as the consumer pulls values, and an early break stops realization.

Idiomatic use:

for v := range vm.Iter(result) {
    // process v
}

Composes with slices.Collect, slices.Filter, etc.

func MapEntryKV added in v1.6.0

func MapEntryKV(entry Value) (Value, Value, bool)

func NumEq

func NumEq(a, b Value) bool

NumEq tests Clojure = numeric equality. Exact integers compare across fixed/big integer representations, floating values compare by value, and BigDecimal only compares with BigDecimal.

func NumEquivalent added in v1.8.0

func NumEquivalent(a, b Value) bool

NumEquivalent tests broad numeric equivalence for == and numeric predicates.

func NumGe

func NumGe(a, b Value) (bool, error)

func NumGt

func NumGt(a, b Value) (bool, error)

NumGt returns true if a > b.

func NumLe

func NumLe(a, b Value) (bool, error)

func NumLt

func NumLt(a, b Value) (bool, error)

NumLt returns true if a < b.

func OpcodeSetSignature added in v1.12.0

func OpcodeSetSignature() (count int, hash uint64)

OpcodeSetSignature identifies this VM's opcode set: the opcode count and an FNV-64a hash of the mnemonics joined in enum order. Bytecode bundles embed it at encode time (bytecode.CapOpcodeSet) so a decoder on a VM with a different opcode enum — opcodes inserted, removed, or reordered — can reject the bundle instead of executing shifted opcodes.

func OpcodeToString

func OpcodeToString(op int32) string

func RecordOpcode added in v1.9.0

func RecordOpcode(prevOp, currOp uint8)

RecordOpcode is called from Frame.Run on every dispatch when ProfilingEnabled is true. prevOp is the previous opcode byte (or 0 at frame start).

func RecoverPanic added in v1.12.0

func RecoverPanic(errp *error)

RecoverPanic catches a thrownPanic and converts it back to an error return. It also catches arbitrary Go panics and converts them to ExecutionErrors so that they produce let-go errors instead of crashing with Go stack traces. Call directly as a deferred function: defer RecoverPanic(&err).

func ReleaseFrame

func ReleaseFrame(f *Frame)

ReleaseFrame returns a frame to the pool. We don't clear stack slots — they'll be overwritten on reuse. We only nil out the large reference fields to avoid pinning code/const objects.

func ResetLookupStats added in v1.11.1

func ResetLookupStats()

func ResetProfile added in v1.9.0

func ResetProfile()

ResetProfile zeroes all counters.

func SafeString added in v1.12.0

func SafeString(value Value) (result string, err error)

SafeString renders a value across the same panic-to-error boundary used by VM invocation. Printing can realize lazy values, so top-level callers must not call Value.String directly.

func SeqIsEmpty added in v1.8.0

func SeqIsEmpty(s Seq) bool

SeqIsEmpty reports whether a Seq is exhausted. Encapsulates the two sentinels — Go nil and the EmptyList singleton — that let-go uses interchangeably to signal end-of-sequence.

Use this to avoid the common `for s != nil && s != EmptyList` pattern.

func SeqValues added in v1.8.0

func SeqValues(s Seq) iter.Seq[Value]

SeqValues returns an iter.Seq[Value] that walks a Seq from a known Seq starting point. Use when you already have a Seq; use Iter when you have a Value (which may be Sequable or non-seq).

func SetCoreNamespace added in v1.8.0

func SetCoreNamespace(ns *Namespace)

SetCoreNamespace registers clojure.core for the warn-on-shadow check. Called once during rt initialization.

func SetLookupStatsEnabled added in v1.11.1

func SetLookupStatsEnabled(enabled bool)

func SetNSLookup

func SetNSLookup(fn func(string) *Namespace)

SetNSLookup sets the global namespace lookup function.

func SetSuppressShadowWarn added in v1.12.0

func SetSuppressShadowWarn(v bool)

SetSuppressShadowWarn toggles the warn-on-core-shadow message. Set true only around trusted internal re-registration (init-time), and reset to false after.

func SetValueEquals added in v1.2.0

func SetValueEquals(fn func(a, b Value) bool)

SetValueEquals sets the equality function (called by rt package during init).

func ToBigInt

func ToBigInt(v Value) (*big.Int, bool)

func ToFloat

func ToFloat(v Value) (float64, bool)

ToFloat converts any numeric Value to float64.

func ToInt

func ToInt(v Value) (int, bool)

ToInt converts a numeric Value to int if possible.

func ToRat added in v1.5.0

func ToRat(v Value) (*big.Rat, bool)

ToRat converts a Value to *big.Rat if possible.

func ToStruct

func ToStruct[T any](r *Record) (T, error)

ToStruct converts a Record back to a Go struct T. Uses the fast path (returns original) if the Record hasn't been mutated.

Types

type ArrayChunk added in v1.9.0

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

ArrayChunk is a slice-backed IChunk. It uses an off/end window over a shared backing array so DropFirst is allocation-free.

func NewArrayChunk added in v1.9.0

func NewArrayChunk(vs []Value, off, end int) *ArrayChunk

NewArrayChunk wraps vs[off:end] as an IChunk. The slice is shared; callers must treat it as immutable from this point.

func NewArrayChunkFromValues added in v1.9.0

func NewArrayChunkFromValues(vs []Value) *ArrayChunk

NewArrayChunkFromValues copies vs into a fresh chunk. Convenience for callers that don't already have a stable backing slice.

func (*ArrayChunk) ChunkCount added in v1.9.0

func (c *ArrayChunk) ChunkCount() int

func (*ArrayChunk) Count added in v1.9.0

func (c *ArrayChunk) Count() Value

Counted lets Lisp `(count chunk)` work on a chunk directly.

func (*ArrayChunk) DropFirst added in v1.9.0

func (c *ArrayChunk) DropFirst() IChunk

func (*ArrayChunk) Nth added in v1.9.0

func (c *ArrayChunk) Nth(i int) Value

func (*ArrayChunk) RawCount added in v1.9.0

func (c *ArrayChunk) RawCount() int

func (*ArrayChunk) String added in v1.9.0

func (c *ArrayChunk) String() string

func (*ArrayChunk) Type added in v1.9.0

func (c *ArrayChunk) Type() ValueType

func (*ArrayChunk) Unbox added in v1.9.0

func (c *ArrayChunk) Unbox() any

func (*ArrayChunk) ValueAt added in v1.9.0

func (c *ArrayChunk) ValueAt(key Value) Value

Lookup so `(nth chunk i)` and `(get chunk i)` work.

func (*ArrayChunk) ValueAtOr added in v1.9.0

func (c *ArrayChunk) ValueAtOr(key Value, dflt Value) Value

type ArrayKind added in v1.3.1

type ArrayKind int

ArrayKind discriminates the element type of a TypedArray.

const (
	ArrayByte   ArrayKind = iota // backing: []byte
	ArrayInt                     // backing: []int64
	ArrayFloat                   // backing: []float64
	ArrayObject                  // backing: []Value
)

type ArrayVector

type ArrayVector []Value

ArrayVector is boxed singly linked list that can hold other Values.

func (ArrayVector) Arity

func (l ArrayVector) Arity() int

func (ArrayVector) Assoc

func (l ArrayVector) Assoc(k Value, v Value) Associative

func (ArrayVector) Conj

func (l ArrayVector) Conj(val Value) Collection

func (ArrayVector) Cons

func (l ArrayVector) Cons(val Value) Seq

Cons implements Seq

func (ArrayVector) Contains

func (l ArrayVector) Contains(value Value) Boolean

func (ArrayVector) Count

func (l ArrayVector) Count() Value

Count implements Collection

func (ArrayVector) Dissoc

func (l ArrayVector) Dissoc(k Value) Associative

func (ArrayVector) Empty

func (l ArrayVector) Empty() Collection

Empty implements Collection

func (ArrayVector) Equals

func (l ArrayVector) Equals(other Value) bool

Equals implements value equality for ArrayVector

func (ArrayVector) First

func (l ArrayVector) First() Value

First implements Seq

func (ArrayVector) Hash

func (l ArrayVector) Hash() uint32

Type implements Value Hash implements Hashable. Computed from elements.

func (ArrayVector) Invoke

func (l ArrayVector) Invoke(pargs []Value) (Value, error)

func (ArrayVector) Meta

func (l ArrayVector) Meta() Value

Meta implements IMeta. ArrayVector doesn't store meta, always returns NIL.

func (ArrayVector) More

func (l ArrayVector) More() Seq

More implements Seq

func (ArrayVector) Next

func (l ArrayVector) Next() Seq

Next implements Seq

func (ArrayVector) Nth added in v1.11.0

func (l ArrayVector) Nth(i int) Value

func (ArrayVector) RawCount

func (l ArrayVector) RawCount() int

func (ArrayVector) Seq

func (l ArrayVector) Seq() Seq

func (ArrayVector) SeqFrom added in v1.12.0

func (l ArrayVector) SeqFrom(i int) Seq

SeqFrom returns a seq over v starting at index i, or nil when i is past the end. This lets callers step into a vector (e.g. next/rest fast paths) with a single allocation instead of Seq()+Next().

func (ArrayVector) String

func (l ArrayVector) String() string

func (ArrayVector) Type

func (l ArrayVector) Type() ValueType

func (ArrayVector) Unbox

func (l ArrayVector) Unbox() any

Unbox implements Value

func (ArrayVector) ValueAt

func (l ArrayVector) ValueAt(key Value) Value

func (ArrayVector) ValueAtOr

func (l ArrayVector) ValueAtOr(key Value, dflt Value) Value

func (ArrayVector) WithMeta

func (l ArrayVector) WithMeta(m Value) Value

WithMeta implements IMeta. Promotes to PersistentVector to carry meta.

type ArrayVectorSeq

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

ArrayVectorSeq is a lightweight seq view over an ArrayVector. ChunkedFirst hands back a fresh *ArrayChunk window over the immutable backing array (the slice is shared, not copied) — a distinct chunk value, so the seq node itself is never mutated and stays safe to share across goroutines.

Chunk sizes GROW geometrically from 1 (1, 2, 4, 8, … clamped to length) rather than a fixed 32 quantum. The size-1 head chunk keeps `first`/short- circuit consumption element-wise (no over-realization), while the doubling amortizes longer walks — the allocation-minimizing shape given that ArrayVectors are overwhelmingly tiny (avg ~1.4 elements).

func (*ArrayVectorSeq) ChunkedFirst added in v1.12.0

func (s *ArrayVectorSeq) ChunkedFirst() IChunk

ChunkedFirst returns a fresh chunk window over [i, i+curChunkLen) of the immutable backing array (clamped to the end). It must be a distinct *ArrayChunk — NOT this seq node and NOT a field on it: an ArrayVectorSeq is a persistent value shared freely across goroutines, so writing a scratch field here would race concurrent calls on the same node (TestArrayVectorSeqChunked FirstRace), and returning s itself would make the chunk also a Seq and pollute chunk-vs-seq interface dispatch. The one small ArrayChunk descriptor allocated here (the backing slice is shared, not copied) is the cost of both.

func (*ArrayVectorSeq) ChunkedMore added in v1.12.0

func (s *ArrayVectorSeq) ChunkedMore() Seq

ChunkedMore is ChunkedNext but returns EmptyList (not nil) at the end.

func (*ArrayVectorSeq) ChunkedNext added in v1.12.0

func (s *ArrayVectorSeq) ChunkedNext() Seq

ChunkedNext advances past this chunk and DOUBLES the quantum, returning the seq positioned at the start of the next (larger) chunk, or nil at the end.

func (*ArrayVectorSeq) Conj

func (s *ArrayVectorSeq) Conj(val Value) Collection

func (*ArrayVectorSeq) Cons

func (s *ArrayVectorSeq) Cons(val Value) Seq

func (*ArrayVectorSeq) Count

func (s *ArrayVectorSeq) Count() Value

func (*ArrayVectorSeq) Empty

func (s *ArrayVectorSeq) Empty() Collection

func (*ArrayVectorSeq) First

func (s *ArrayVectorSeq) First() Value

func (*ArrayVectorSeq) More

func (s *ArrayVectorSeq) More() Seq

func (*ArrayVectorSeq) Next

func (s *ArrayVectorSeq) Next() Seq

func (*ArrayVectorSeq) Nth added in v1.11.0

func (s *ArrayVectorSeq) Nth(i int) Value

Nth implements Indexed: positional access by integer index.

func (*ArrayVectorSeq) RawCount

func (s *ArrayVectorSeq) RawCount() int

func (*ArrayVectorSeq) Seq

func (s *ArrayVectorSeq) Seq() Seq

func (*ArrayVectorSeq) String

func (s *ArrayVectorSeq) String() string

func (*ArrayVectorSeq) Type

func (s *ArrayVectorSeq) Type() ValueType

func (*ArrayVectorSeq) Unbox

func (s *ArrayVectorSeq) Unbox() any

func (*ArrayVectorSeq) ValueAt

func (s *ArrayVectorSeq) ValueAt(key Value) Value

ValueAt implements Lookup for ArrayVectorSeq so that `get` works on seq views.

func (*ArrayVectorSeq) ValueAtOr

func (s *ArrayVectorSeq) ValueAtOr(key Value, dflt Value) Value

ValueAtOr implements Lookup for ArrayVectorSeq.

type Associative

type Associative interface {
	Value
	Assoc(Value, Value) Associative
	Dissoc(Value) Associative
}

type Atom

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

Atom is a thread-safe mutable reference. Swap uses optimistic concurrency with a generation counter — no value comparison needed. The function may be called multiple times under contention.

func NewAtom

func NewAtom(root Value) *Atom

func NewAtomWithMetaValidator added in v1.8.0

func NewAtomWithMetaValidator(root Value, meta Value, validator Fn) (*Atom, error)

func (*Atom) AddWatch

func (a *Atom) AddWatch(key Value, fn Fn)

func (*Atom) AlterMeta

func (a *Atom) AlterMeta(fn Fn, args []Value) (Value, error)

func (*Atom) CompareAndSet added in v1.10.0

func (a *Atom) CompareAndSet(oldVal, newVal Value) (bool, error)

CompareAndSet atomically sets the value to newVal only if the current value is identical to oldVal, returning true on success. Identity comparison (==), matching Clojure's compare-and-set!.

func (*Atom) Deref

func (a *Atom) Deref() Value

func (*Atom) Hash added in v1.8.0

func (a *Atom) Hash() uint32

func (*Atom) Meta

func (a *Atom) Meta() Value

func (*Atom) RemoveWatch

func (a *Atom) RemoveWatch(key Value)

func (*Atom) Reset

func (a *Atom) Reset(newVal Value) (Value, error)

func (*Atom) String

func (a *Atom) String() string

func (*Atom) Swap

func (a *Atom) Swap(fn Fn, args []Value) (Value, error)

Swap applies fn to the current value and atomically sets the result. The fn is called outside the lock; if the value changed during computation, fn is retried with the new value (like Clojure's swap!).

func (*Atom) Type

func (a *Atom) Type() ValueType

func (*Atom) Unbox

func (a *Atom) Unbox() any

func (*Atom) Validator added in v1.8.0

func (a *Atom) Validator() Value

func (*Atom) WithMeta

func (a *Atom) WithMeta(m Value) Value

type BigDecimal added in v1.5.0

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

BigDecimal wraps *math/big.Float as a VM value with arbitrary precision.

func MustBigDecimalFromString added in v1.11.0

func MustBigDecimalFromString(s string) *BigDecimal

MustBigDecimalFromString builds a BigDecimal from a string, panicking on an unparseable input. Intended for gogen-emitted constant literals, whose source strings were already validated at read time, so the panic is unreachable in generated code — it exists only to give a single-value expression form (the (value, ok) signature of NewBigDecimalFromString can't be used inline).

func NewBigDecimal added in v1.5.0

func NewBigDecimal(v *big.Float) *BigDecimal

func NewBigDecimalFromBigInt added in v1.12.0

func NewBigDecimalFromBigInt(n *big.Int) *BigDecimal

func NewBigDecimalFromFloat64 added in v1.5.0

func NewBigDecimalFromFloat64(f float64) *BigDecimal

func NewBigDecimalFromInt64 added in v1.5.0

func NewBigDecimalFromInt64(n int64) *BigDecimal

func NewBigDecimalFromString added in v1.5.0

func NewBigDecimalFromString(s string) (*BigDecimal, bool)

func (*BigDecimal) Equals added in v1.5.0

func (b *BigDecimal) Equals(other Value) bool

Equals compares BigDecimals.

func (*BigDecimal) GoString added in v1.5.0

func (b *BigDecimal) GoString() string

func (*BigDecimal) Hash added in v1.5.0

func (b *BigDecimal) Hash() uint32

Hash implements Hashable.

func (*BigDecimal) String added in v1.5.0

func (b *BigDecimal) String() string

func (*BigDecimal) ToFloat64 added in v1.5.0

func (b *BigDecimal) ToFloat64() float64

ToFloat64 converts to float64.

func (*BigDecimal) Type added in v1.5.0

func (b *BigDecimal) Type() ValueType

func (*BigDecimal) Unbox added in v1.5.0

func (b *BigDecimal) Unbox() any

func (*BigDecimal) Val added in v1.5.0

func (b *BigDecimal) Val() *big.Float

type BigInt

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

BigInt wraps *math/big.Int as a VM value.

func MustBigIntFromString added in v1.11.0

func MustBigIntFromString(s string) *BigInt

MustBigIntFromString builds a BigInt from its base-10 string form, panicking on an unparseable input. Intended for gogen-emitted constant literals (the source was validated at read time, so the panic is unreachable in generated code); gives a single-value expression form the (value, ok) constructor can't.

func NewBigInt

func NewBigInt(v *big.Int) *BigInt

func NewBigIntFromInt64

func NewBigIntFromInt64(n int64) *BigInt

func NewBigIntFromString

func NewBigIntFromString(s string) (*BigInt, bool)

func (*BigInt) Equals

func (b *BigInt) Equals(other *BigInt) bool

Equals compares two BigInts.

func (*BigInt) GoString

func (b *BigInt) GoString() string

BigIntFromValue returns a string representation suitable for printing.

func (*BigInt) Hash

func (b *BigInt) Hash() uint32

Hash implements Hashable — consistent with Int.Hash() for values that fit in int64.

func (*BigInt) String

func (b *BigInt) String() string

func (*BigInt) ToInt64

func (b *BigInt) ToInt64() (int64, bool)

ToInt64 returns the int64 value if it fits, or false.

func (*BigInt) Type

func (b *BigInt) Type() ValueType

func (*BigInt) Unbox

func (b *BigInt) Unbox() any

func (*BigInt) Val

func (b *BigInt) Val() *big.Int

type BindingSnapshot added in v1.8.0

type BindingSnapshot map[*Var][]Value

func SnapshotBindings added in v1.8.0

func SnapshotBindings() BindingSnapshot

SnapshotBindings captures the root context's dynamic bindings — the explicit-propagation primitive a goroutine spawn hands to its child.

type BlockingDeref added in v1.10.0

type BlockingDeref interface {
	DerefTimeout(timeoutMs int64, timeoutVal Value) Value
}

BlockingDeref is a reference whose value may not be available yet (promise, future). DerefTimeout blocks up to timeoutMs for the value, returning timeoutVal on timeout. Backs Clojure's 3-arg deref.

type Boolean

type Boolean bool

Boolean is either TRUE or FALSE

const FALSE Boolean = false

FALSE is Boolean

const TRUE Boolean = true

TRUE is Boolean

func (Boolean) Hash

func (n Boolean) Hash() uint32

Hash implements Hashable.

func (Boolean) String

func (n Boolean) String() string

func (Boolean) Type

func (n Boolean) Type() ValueType

Type implements Value

func (Boolean) Unbox

func (n Boolean) Unbox() any

Unbox implements Value

type Boxed

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

func NewBoxed

func NewBoxed(value any) *Boxed

func (*Boxed) Hash added in v1.11.0

func (n *Boxed) Hash() uint32

Hash implements Hashable. Without it, hashValue falls back to computeHash -> hashBytes(String()), which formats the boxed value via fmt.Sprintf("%v") on EVERY hash — catastrophic when boxed values (e.g. SourceInfo) are embedded in IR vectors that get hashed repeatedly during lowering (= comparisons, CSE, map/set keys). *Boxed is an immutable pointer, so we compute the String-based hash once and cache it. The value is identical to the old computeHash fallback, so map/set semantics are unchanged — only the repeated Sprintf is eliminated.

func (*Boxed) InvokeMethod

func (n *Boxed) InvokeMethod(methodName Symbol, args []Value) (Value, error)

func (*Boxed) String

func (n *Boxed) String() string

func (*Boxed) Type

func (n *Boxed) Type() ValueType

Type implements Value

func (*Boxed) Unbox

func (n *Boxed) Unbox() any

Unbox implements Value

func (*Boxed) ValueAt

func (n *Boxed) ValueAt(key Value) Value

func (*Boxed) ValueAtOr

func (n *Boxed) ValueAtOr(key Value, dflt Value) Value

type Chan

type Chan chan Value

Chan is either TRUE or FALSE

func (Chan) String

func (n Chan) String() string

func (Chan) Type

func (n Chan) Type() ValueType

Type implements Value

func (Chan) Unbox

func (n Chan) Unbox() any

Unbox implements Value

type Char

type Char rune

Char is boxed rune

func (Char) Hash

func (l Char) Hash() uint32

Hash implements Hashable.

func (Char) String

func (l Char) String() string

func (Char) Type

func (l Char) Type() ValueType

Type implements Value

func (Char) Unbox

func (l Char) Unbox() any

Unbox implements Unbox

type ChunkBuffer added in v1.9.0

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

ChunkBuffer is a mutable builder for an ArrayChunk. Use Append to fill, then Chunk() to finalize — the returned IChunk takes ownership of the buffer.

func NewChunkBuffer added in v1.9.0

func NewChunkBuffer(cap int) *ChunkBuffer

NewChunkBuffer returns a buffer pre-sized for cap elements. Append grows beyond cap if needed.

func (*ChunkBuffer) Append added in v1.9.0

func (b *ChunkBuffer) Append(v Value)

func (*ChunkBuffer) Chunk added in v1.9.0

func (b *ChunkBuffer) Chunk() IChunk

Chunk finalizes the buffer into an IChunk and clears the buffer so further Append calls operate on a fresh backing slice.

func (*ChunkBuffer) Count added in v1.9.0

func (b *ChunkBuffer) Count() Value

Counted: lets `(count buf)` return the number of elements buffered so far.

func (*ChunkBuffer) RawCount added in v1.9.0

func (b *ChunkBuffer) RawCount() int

func (*ChunkBuffer) String added in v1.9.0

func (b *ChunkBuffer) String() string

func (*ChunkBuffer) Type added in v1.9.0

func (b *ChunkBuffer) Type() ValueType

ChunkBuffer satisfies Value so it can be threaded through Lisp.

func (*ChunkBuffer) Unbox added in v1.9.0

func (b *ChunkBuffer) Unbox() any

type ChunkedCons added in v1.9.0

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

ChunkedCons pairs a non-empty IChunk with a tail seq. It is itself both a Seq and an IChunkedSeq: the chunk is the head batch, `more` is whatever comes after.

func NewChunkedCons added in v1.9.0

func NewChunkedCons(chunk IChunk, more Seq) *ChunkedCons

NewChunkedCons returns a ChunkedCons. The chunk must be non-empty; callers that may have an empty chunk should use ConsChunk which folds the empty case down to `more`.

func (*ChunkedCons) ChunkedFirst added in v1.9.0

func (c *ChunkedCons) ChunkedFirst() IChunk

func (*ChunkedCons) ChunkedMore added in v1.9.0

func (c *ChunkedCons) ChunkedMore() Seq

func (*ChunkedCons) ChunkedNext added in v1.9.0

func (c *ChunkedCons) ChunkedNext() Seq

func (*ChunkedCons) Cons added in v1.9.0

func (c *ChunkedCons) Cons(val Value) Seq

func (*ChunkedCons) First added in v1.9.0

func (c *ChunkedCons) First() Value

func (*ChunkedCons) Hash added in v1.9.0

func (c *ChunkedCons) Hash() uint32

Hash implements Hashable, mirroring Cons/List ordered hashing so the three seq surfaces equate in sets and maps.

func (*ChunkedCons) More added in v1.9.0

func (c *ChunkedCons) More() Seq

func (*ChunkedCons) Next added in v1.9.0

func (c *ChunkedCons) Next() Seq

func (*ChunkedCons) Seq added in v1.9.0

func (c *ChunkedCons) Seq() Seq

func (*ChunkedCons) String added in v1.9.0

func (c *ChunkedCons) String() string

func (*ChunkedCons) Type added in v1.9.0

func (c *ChunkedCons) Type() ValueType

func (*ChunkedCons) Unbox added in v1.9.0

func (c *ChunkedCons) Unbox() any

type Closure

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

func (*Closure) Arity

func (l *Closure) Arity() int

func (*Closure) Invoke

func (l *Closure) Invoke(pargs []Value) (result Value, err error)

func (*Closure) Meta added in v1.12.0

func (l *Closure) Meta() Value

Meta implements IMeta.

func (*Closure) String

func (l *Closure) String() string

func (*Closure) Type

func (l *Closure) Type() ValueType

func (*Closure) Unbox

func (l *Closure) Unbox() any

Unbox implements Unbox

func (*Closure) WithMeta added in v1.12.0

func (l *Closure) WithMeta(m Value) Value

WithMeta implements IMeta. Returns a copy carrying m; the compiled fn and the closed-over slots are immutable at call time, so sharing them is safe and only the metadata differs. Lets (with-meta (fn ...) m) round-trip through meta, which spying/instrumentation libraries (e.g. bond) rely on.

type CodeChunk

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

func NewCodeChunk

func NewCodeChunk(consts *Consts) *CodeChunk

func NewCodeChunkWithCapacity added in v1.11.1

func NewCodeChunkWithCapacity(consts *Consts, n int) *CodeChunk

NewCodeChunkWithCapacity creates an empty chunk with preallocated code storage for n instructions.

func (*CodeChunk) AddLocalVar added in v1.10.0

func (c *CodeChunk) AddLocalVar(slot int, name string)

AddLocalVar records the source name bound to a stack slot (debug info).

func (*CodeChunk) AddSourceInfo

func (c *CodeChunk) AddSourceInfo(info SourceInfo)

AddSourceInfo records the source location for the current bytecode offset.

func (*CodeChunk) AddSourceInfoAt added in v1.11.1

func (c *CodeChunk) AddSourceInfoAt(ip int, info SourceInfo)

AddSourceInfoAt records the source location for the provided bytecode offset.

func (*CodeChunk) Append

func (c *CodeChunk) Append(insts ...int32)

func (*CodeChunk) Append32

func (c *CodeChunk) Append32(val int)

func (*CodeChunk) AppendChunk

func (c *CodeChunk) AppendChunk(o *CodeChunk)

func (*CodeChunk) Code added in v1.3.0

func (c *CodeChunk) Code() []int32

Code returns the bytecode slice.

func (*CodeChunk) Consts added in v1.3.0

func (c *CodeChunk) Consts() *Consts

Consts returns the const pool reference.

func (*CodeChunk) Debug

func (c *CodeChunk) Debug()

func (*CodeChunk) Get

func (c *CodeChunk) Get(idx int) (int32, error)

func (*CodeChunk) Get32

func (c *CodeChunk) Get32(idx int) (int, error)

func (*CodeChunk) GetSourceMap added in v1.3.0

func (c *CodeChunk) GetSourceMap() *SourceMap

GetSourceMap returns the source map, may be nil.

func (*CodeChunk) Length

func (c *CodeChunk) Length() int

func (*CodeChunk) LocalVars added in v1.10.0

func (c *CodeChunk) LocalVars() []LocalVar

LocalVars returns the chunk's local-variable debug table (may be nil).

func (*CodeChunk) LookupSource

func (c *CodeChunk) LookupSource(ip int) *SourceInfo

LookupSource finds the source location for a given instruction pointer.

func (*CodeChunk) MaxStack added in v1.3.0

func (c *CodeChunk) MaxStack() int

MaxStack returns the max stack depth.

func (*CodeChunk) ReserveLocalVars added in v1.11.1

func (c *CodeChunk) ReserveLocalVars(n int)

ReserveLocalVars ensures the local-var debug table can hold n entries without growing.

func (*CodeChunk) ReserveSourceMap added in v1.11.1

func (c *CodeChunk) ReserveSourceMap(n int)

ReserveSourceMap ensures the source-map backing storage can hold n entries without growing.

func (*CodeChunk) SetMaxStack

func (c *CodeChunk) SetMaxStack(max int)

func (*CodeChunk) SetSourceMap added in v1.12.0

func (c *CodeChunk) SetSourceMap(sm *SourceMap)

SetSourceMap replaces the chunk's source map. Used by the decoder to inject a lazily-materialized map (whose entries are decoded on first Lookup) so bundle load skips per-chunk source-map allocation for the common no-error path.

func (*CodeChunk) Update32

func (c *CodeChunk) Update32(address int, value int32)

type Collection

type Collection interface {
	Value
	Counted
	Empty() Collection
	Conj(Value) Collection
}

Collection is implemented by all collections

type Comparator added in v1.5.0

type Comparator func(a, b Value) (int, error)

Comparator is a function that compares two Values, returning -1, 0, or 1.

type Cons

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

Cons is a cons cell - a pair of (first, rest) where rest is a seq. This is the fundamental building block for consing onto any seq.

func NewCons

func NewCons(first Value, more Seq) *Cons

func (*Cons) Conj

func (c *Cons) Conj(val Value) Collection

func (*Cons) Cons

func (c *Cons) Cons(val Value) Seq

func (*Cons) Count

func (c *Cons) Count() Value

func (*Cons) Empty

func (c *Cons) Empty() Collection

func (*Cons) First

func (c *Cons) First() Value

func (*Cons) Hash added in v1.8.0

func (c *Cons) Hash() uint32

Hash implements Hashable using Clojure's ordered-collection Murmur3 mix. Must match *List.Hash so a Cons of the same elements equates in sets/maps.

func (*Cons) More

func (c *Cons) More() Seq

func (*Cons) Next

func (c *Cons) Next() Seq

func (*Cons) RawCount

func (c *Cons) RawCount() int

func (*Cons) Seq

func (c *Cons) Seq() Seq

func (*Cons) String

func (c *Cons) String() string

func (*Cons) Type

func (c *Cons) Type() ValueType

func (*Cons) Unbox

func (c *Cons) Unbox() any

type Consts

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

Consts is a constant pool with O(1) indexed access and O(1) amortized interning. Uses a custom open-addressing hash map (not Go's built-in map) so that all Value types — including slices like ArrayVector — can be interned without panicking.

Supports optional layering: a child pool references a parent. Indices 0..base-1 are in the parent, base.. are in the child. Only child entries are returned by Values() for serialization.

func NewChildConsts added in v1.3.0

func NewChildConsts(parent *Consts) *Consts

NewChildConsts creates a child pool layered on top of parent. Parent values are accessible by index but not serialized with this pool.

func NewConsts

func NewConsts() *Consts

NewConsts creates a root constant pool.

func (*Consts) AllValues added in v1.3.0

func (c *Consts) AllValues() []Value

AllValues returns all values including parent.

func (*Consts) Append added in v1.3.0

func (c *Consts) Append(v Value) int

Append adds a value at the next index without deduplication. Used when loading pre-compiled bytecode where indices must match the original.

func (*Consts) Base added in v1.3.0

func (c *Consts) Base() int

Base returns the starting global index for this layer.

func (*Consts) Intern

func (c *Consts) Intern(v Value) int

Intern returns the index for v, adding it if not already present. Checks parent pool first (if any) to reuse existing indices.

func (*Consts) Parent added in v1.3.0

func (c *Consts) Parent() *Consts

Parent returns the parent pool, or nil.

func (*Consts) Reserve added in v1.11.1

func (c *Consts) Reserve(n int)

Reserve ensures this const pool can append at least n additional values without growing its value slice or hash table.

func (*Consts) Values added in v1.3.0

func (c *Consts) Values() []Value

Values returns only this layer's values (for serialization).

type Counted

type Counted interface {
	Value
	RawCount() int
	Count() Value
}

type DType added in v1.5.0

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

DType is a dynamically-created ValueType for a deftype. Unlike RecordType, instances of a DType do NOT implement map behavior (no Associative, Lookup, Seqable, or Collection interfaces).

func NewDType added in v1.5.0

func NewDType(name string, fields []Symbol) *DType

func (*DType) Box added in v1.5.0

func (t *DType) Box(bare any) (Value, error)

func (*DType) Fields added in v1.5.0

func (t *DType) Fields() []Symbol

func (*DType) Name added in v1.5.0

func (t *DType) Name() string

func (*DType) String added in v1.5.0

func (t *DType) String() string

func (*DType) Type added in v1.5.0

func (t *DType) Type() ValueType

func (*DType) Unbox added in v1.5.0

func (t *DType) Unbox() any

type DTypeInstance added in v1.5.0

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

DTypeInstance is a value created by a deftype constructor. Fields are stored in a flat array, accessed by symbol name via Receiver.

func NewDTypeInstance added in v1.5.0

func NewDTypeInstance(dt *DType, fields []Value) *DTypeInstance

func (*DTypeInstance) DType added in v1.5.0

func (d *DTypeInstance) DType() *DType

DType returns the type.

func (*DTypeInstance) Equals added in v1.5.0

func (d *DTypeInstance) Equals(other Value) bool

Equals: reference identity, matching JVM deftype semantics.

func (*DTypeInstance) Fields added in v1.5.0

func (d *DTypeInstance) Fields() []Value

Fields returns the field values.

func (*DTypeInstance) Hash added in v1.5.0

func (d *DTypeInstance) Hash() uint32

Hash: identity-based (matches JVM default hashCode).

func (*DTypeInstance) InvokeMethod added in v1.5.0

func (d *DTypeInstance) InvokeMethod(name Symbol, args []Value) (Value, error)

InvokeMethod implements Receiver so (.fieldname instance) returns the field. Both (.field x) and the explicit field-access form (.-field x) are accepted: the reader hands the latter through as the member symbol "-field", so a leading "-" is stripped before the field lookup (Clojure's .-field syntax).

func (*DTypeInstance) Meta added in v1.10.0

func (d *DTypeInstance) Meta() Value

Meta implements IMeta.

func (*DTypeInstance) SetField added in v1.10.0

func (d *DTypeInstance) SetField(name Symbol, val Value) error

SetField mutates a field in place by name. Backs cljs-style ^:mutable deftype fields. UNSYNCHRONIZED: not safe for concurrent access; callers must ensure exclusive access (single-threaded use, atoms, or explicit locks). A Go nil is normalized to NIL to preserve the field-value invariant.

func (*DTypeInstance) String added in v1.5.0

func (d *DTypeInstance) String() string

func (*DTypeInstance) Type added in v1.5.0

func (d *DTypeInstance) Type() ValueType

func (*DTypeInstance) Unbox added in v1.5.0

func (d *DTypeInstance) Unbox() any

func (*DTypeInstance) WithMeta added in v1.10.0

func (d *DTypeInstance) WithMeta(m Value) Value

WithMeta implements IMeta. Returns a copy carrying m; field storage is shared with the original (metadata does not affect fields).

type Delay

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

Delay wraps a thunk (zero-arg function) that is evaluated at most once. The result is cached after the first call to Force().

func NewDelay

func NewDelay(fn Fn) *Delay

func (*Delay) Deref

func (d *Delay) Deref() Value

func (*Delay) Force

func (d *Delay) Force() (Value, error)

func (*Delay) IsRealized

func (d *Delay) IsRealized() bool

func (*Delay) String

func (d *Delay) String() string

func (*Delay) Type

func (d *Delay) Type() ValueType

func (*Delay) Unbox

func (d *Delay) Unbox() any

type ExInfo

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

ExInfo is an exception value carrying a message and data map. Equivalent to Clojure's ExceptionInfo.

func NewExInfo

func NewExInfo(message string, data *PersistentMap, cause error) *ExInfo

func NewExInfoWithClass added in v1.12.0

func NewExInfoWithClass(class *ExceptionClass, message string, cause error) *ExInfo

NewExInfoWithClass builds an exception value tagged with a java.lang.* class (constructed via Exception. and friends, or a wrapped Go runtime error). Tagged values carry no data map; ex-data returns nil for them.

func (*ExInfo) Cause

func (e *ExInfo) Cause() error

func (*ExInfo) Data

func (e *ExInfo) Data() *PersistentMap

func (*ExInfo) Error

func (e *ExInfo) Error() string

func (*ExInfo) InvokeMethod added in v1.10.0

func (e *ExInfo) InvokeMethod(name Symbol, args []Value) (Value, error)

InvokeMethod implements Receiver so the JVM-interop method forms (.getMessage ex) / (.getCause ex) dispatch to an ex-info value. This lets libraries that branch on (instance? Throwable ex) and then call .getMessage — e.g. medley's ex-message/ex-cause on their :clj branch — work against let-go ex-info values. Mirrors the semantics of core's ex-message/ex-cause.

func (*ExInfo) Message

func (e *ExInfo) Message() string

func (*ExInfo) Meta added in v1.10.0

func (e *ExInfo) Meta() Value

Meta / WithMeta implement IMeta. Type hints compile to runtime metadata in let-go, so medley's (.getMessage ^Throwable ex) reaches (with-meta ex ...); supporting metadata lets that hinted call work. WithMeta returns a copy that is still *ExInfo, preserving Type()==ExInfoType (so (instance? Throwable ex) stays true) and InvokeMethod (so .getMessage/.getCause still dispatch).

func (*ExInfo) String

func (e *ExInfo) String() string

func (*ExInfo) Type

func (e *ExInfo) Type() ValueType

func (*ExInfo) Unbox

func (e *ExInfo) Unbox() any

func (*ExInfo) WithMeta added in v1.10.0

func (e *ExInfo) WithMeta(m Value) Value

type ExceptionClass added in v1.12.0

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

ExceptionClass is a ValueType representing a JVM-style exception class. Instances form the java.lang.* hierarchy through the parent pointer; the walk in pkg/rt's directTypeAncestors follows it for instance? and typed catch dispatch. Exception VALUES are *ExInfo tagged with one of these classes; there is one Go struct for all exception values, not one per class.

func (*ExceptionClass) Box added in v1.12.0

func (c *ExceptionClass) Box(bare any) (Value, error)

func (*ExceptionClass) Name added in v1.12.0

func (c *ExceptionClass) Name() string

func (*ExceptionClass) Parent added in v1.12.0

func (c *ExceptionClass) Parent() *ExceptionClass

func (*ExceptionClass) String added in v1.12.0

func (c *ExceptionClass) String() string

func (*ExceptionClass) Type added in v1.12.0

func (c *ExceptionClass) Type() ValueType

func (*ExceptionClass) Unbox added in v1.12.0

func (c *ExceptionClass) Unbox() any

type ExecContext added in v1.11.0

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

ExecContext is the single object that resolves an execution's dynamic state — both the dynamic-var binding stack and the structured-concurrency Scope (see docs/design/exec-context-threading.md). It is the *implementer* of invocation and of dynamic resolution: the eval loop, builtins, and goroutine spawn all go through an ExecContext rather than looking state up by goroutine id.

There is always an ExecContext in play. RootExecContext is the process default — its binding stack is the shared global one and its scope is the root Goroutines scope, so code that never asks for isolation behaves exactly as it always has. Per-goroutine isolation is explicit: a spawn hands the child a fresh ExecContext seeded from a snapshot of the parent's (ec.Child()) — carrying the parent's bindings and scope — so goroutines cannot interleave each other's dynamic state, with no goroutine-id lookup and no reuse hazard.

func NewExecContext added in v1.11.0

func NewExecContext() *ExecContext

NewExecContext returns a context with a fresh, empty binding stack.

func NewExecContextFrom added in v1.11.0

func NewExecContextFrom(snap BindingSnapshot) *ExecContext

NewExecContextFrom returns a fresh context whose binding stack is seeded from snap. It is the per-call isolation primitive: bound-fn* captures a snapshot once and builds a fresh context from it on every invocation, so the wrapped function always re-establishes exactly the captured bindings and never leaks pushes between calls or across goroutines.

func (*ExecContext) Bind added in v1.11.0

func (ec *ExecContext) Bind(fn Fn) Fn

Bind pins fn to this context: the returned Fn routes every later call through ec.Invoke, so a callback handed to context-free machinery (Atom retry loops, sort comparators, stored transducer steps) still resolves dynamic vars against the caller's context. At the root this is the identity — plain Invoke already resolves there — so root-context callers pay nothing.

func (*ExecContext) BindingSnapshot added in v1.11.0

func (ec *ExecContext) BindingSnapshot() BindingSnapshot

BindingSnapshot returns a snapshot of this context's current bindings, suitable for passing to NewExecContextFrom to isolate a child context. A nil receiver uses the root context.

func (*ExecContext) Child added in v1.11.0

func (ec *ExecContext) Child() *ExecContext

Child returns a fresh ExecContext seeded from a snapshot of this one's bindings — the explicit-propagation primitive used at goroutine boundaries. A nil receiver seeds from the root context.

func (*ExecContext) Context added in v1.11.0

func (ec *ExecContext) Context() context.Context

Context returns the cancellation context blocking native ops (channel take/put, alts!) select on — the scope's context.

func (*ExecContext) Deref added in v1.11.0

func (ec *ExecContext) Deref(v *Var) Value

func (*ExecContext) Invoke added in v1.11.0

func (ec *ExecContext) Invoke(fn Fn, args []Value) (Value, error)

Invoke runs fn with args in this context. Closures propagate the context to their child frame; context-aware natives receive it; pure functions are invoked unchanged. This is the single dispatch site the eval loop uses.

func (*ExecContext) PopBinding added in v1.11.0

func (ec *ExecContext) PopBinding(v *Var)

func (*ExecContext) PushBinding added in v1.11.0

func (ec *ExecContext) PushBinding(v *Var, val Value)

Exported entry points for runtime builtins (pkg/rt) that resolve dynamic vars against an ExecContext handed to them by ec.Invoke.

func (*ExecContext) Scope added in v1.11.0

func (ec *ExecContext) Scope() *Scope

Scope returns the structured-concurrency scope this context runs under, normalising the nil (root) context to the process-wide Goroutines scope. A nil receiver also resolves to the root.

func (*ExecContext) SetBinding added in v1.11.0

func (ec *ExecContext) SetBinding(v *Var, val Value) bool

SetBinding mutates v's top dynamic binding in this context (thread-local set!), returning false if v has no active binding here so the caller can fall back to the root. Exported for runtime builtins like in-ns.

func (*ExecContext) SetScope added in v1.11.0

func (ec *ExecContext) SetScope(s *Scope)

SetScope installs s as this context's scope. Used by with-scope to open a child scope for a dynamic extent and to restore the previous one on close.

type ExecutionError

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

func NewExecutionError

func NewExecutionError(m string) *ExecutionError

func (*ExecutionError) Error

func (ve *ExecutionError) Error() string

func (*ExecutionError) GetCause

func (ve *ExecutionError) GetCause() error

func (*ExecutionError) WithSource

func (ve *ExecutionError) WithSource(info *SourceInfo) *ExecutionError

func (*ExecutionError) Wrap

func (ve *ExecutionError) Wrap(e error) errors.Error

type Float

type Float float64

Float is boxed float64

func (Float) Hash

func (l Float) Hash() uint32

Hash implements Hashable.

func (Float) String

func (l Float) String() string

func (Float) Type

func (l Float) Type() ValueType

Type implements Value

func (Float) Unbox

func (l Float) Unbox() any

Unbox implements Unbox

type Float32 added in v1.8.0

type Float32 float64

func (Float32) Hash added in v1.8.0

func (l Float32) Hash() uint32

func (Float32) String added in v1.8.0

func (l Float32) String() string

func (Float32) Type added in v1.8.0

func (l Float32) Type() ValueType

func (Float32) Unbox added in v1.8.0

func (l Float32) Unbox() any

type Fn

type Fn interface {
	Value
	Invoke([]Value) (Value, error)
	Arity() int
}

func AsFn added in v1.10.0

func AsFn(fraw Value) (Fn, bool)

AsFn returns fraw as a callable Fn: directly if it already is one, or — when fraw's type satisfies the IFn protocol — wrapped in an adapter that routes calls to its -invoke method. Reports false when fraw is not callable.

type Frame

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

Frame is a single interpreter context

func NewDebugFrame

func NewDebugFrame(code *CodeChunk, args []Value) *Frame

func NewFrame

func NewFrame(code *CodeChunk, args []Value) *Frame

func (*Frame) Run

func (f *Frame) Run() (Value, error)

func (*Frame) RunProtected

func (f *Frame) RunProtected() (result Value, err error)

RunProtected runs the frame with panic recovery for thrownPanic. Use at top-level entry points (REPL, file eval). Internal calls use Run() directly.

type Func

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

func MakeFunc

func MakeFunc(arity int, variadric bool, c *CodeChunk) *Func

func (*Func) Arity

func (l *Func) Arity() int

func (*Func) Chunk added in v1.3.0

func (l *Func) Chunk() *CodeChunk

Chunk returns the code chunk.

func (*Func) FuncName added in v1.3.0

func (l *Func) FuncName() string

FuncName returns the function name.

func (*Func) Invoke

func (l *Func) Invoke(pargs []Value) (result Value, err error)

func (*Func) IsVariadic added in v1.3.0

func (l *Func) IsVariadic() bool

IsVariadic returns whether the function is variadic.

func (*Func) MakeClosure

func (l *Func) MakeClosure() Fn

func (*Func) Meta added in v1.12.0

func (l *Func) Meta() Value

Meta implements IMeta.

func (*Func) SetName

func (l *Func) SetName(n string)

func (*Func) String

func (l *Func) String() string

func (*Func) Type

func (l *Func) Type() ValueType

func (*Func) Unbox

func (l *Func) Unbox() any

Unbox implements Unbox

func (*Func) WithMeta added in v1.12.0

func (l *Func) WithMeta(m Value) Value

WithMeta implements IMeta. Returns a copy carrying m. A capture-free fn is a shared compiler constant pushed by OP_LOAD_CONST, so this MUST copy rather than mutate — otherwise every evaluation of the fn literal would observe the metadata. The chunk is immutable, so sharing it across the copy is safe.

type FuncInterface

type FuncInterface func(any)

type GoPanicError added in v1.9.0

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

GoPanicError wraps an unexpected Go panic (one that is NOT a let-go thrown error) together with the Go stack captured at the recover site. Native-fn crashes — e.g. a `syscall/js: Value.Int on undefined` under WASM, or a nil dereference in a Go builtin — have no let-go source location, so without this the only traceback was an unhelpful `at <fn> (<unknown>)`. The captured Go stack pins the actual crash site (the .go file:line) and FormatError surfaces the let-go-relevant frames.

func (*GoPanicError) Error added in v1.9.0

func (e *GoPanicError) Error() string

func (*GoPanicError) GoStack added in v1.9.0

func (e *GoPanicError) GoStack() string

GoStack returns the raw Go stack trace captured when the panic was recovered.

type Hashable

type Hashable interface {
	Hash() uint32
}

Hashable is implemented by types that cache their hash for fast map lookups.

type IChunk added in v1.9.0

type IChunk interface {
	Value
	ChunkCount() int
	Nth(i int) Value
	DropFirst() IChunk
}

IChunk is a fixed-size, indexable, sliceable batch of Values. Implementations may share backing storage; DropFirst must never mutate.

Note: the per-chunk size is exposed as ChunkCount() rather than Count() because concrete chunks (ArrayChunk, ChunkBuffer) also satisfy the Counted protocol — which requires Count() Value and RawCount() int — and Go interfaces cannot disambiguate two methods with the same name and different return types.

type IChunkedSeq added in v1.9.0

type IChunkedSeq interface {
	Seq
	ChunkedFirst() IChunk
	ChunkedNext() Seq // nil at end
	ChunkedMore() Seq // EmptyList at end
}

IChunkedSeq is a Seq that can yield a whole chunk at a time. Consumers may dispatch on this interface to amortize per-element overhead; the Seq methods (First/Next/More) must remain consistent with the chunked view: First() == ChunkedFirst().Nth(0), Next() walks within the chunk before moving to ChunkedNext().

func AsChunkedSeq added in v1.9.0

func AsChunkedSeq(s Seq) (IChunkedSeq, bool)

AsChunkedSeq returns the chunked view of s if available, resolving through LazySeq wrappers. Returns (cs, true) if s ultimately resolves to a non-empty IChunkedSeq, (nil, false) otherwise (including for empty seqs).

Callers use this to choose a chunked fast path:

if cs, ok := AsChunkedSeq(s); ok {
    // process cs.ChunkedFirst() in bulk, recurse on cs.ChunkedMore()
}
// fallback: one-at-a-time

type IMeta

type IMeta interface {
	Meta() Value          // returns the metadata map, or NIL
	WithMeta(Value) Value // returns a copy of this value with the given metadata
}

IMeta is implemented by values that support metadata.

type Indexed added in v1.11.0

type Indexed interface {
	Value
	Nth(i int) Value
	RawCount() int
}

Indexed marks positional collections — those whose elements are addressed by a 0-based integer index, as opposed to maps/sets (key-addressable) and lazy seqs (sequential-only). `nth` dispatches on this to use an O(1)-ish indexed access without seq traversal. Implementations must satisfy: Nth(i) is valid for 0 <= i < RawCount(); callers bounds-check via RawCount() before calling.

Crucially this excludes maps/sets (which are Lookup+Counted but NOT positional) and transient/chunk types that aren't seqable — so adding a new positional type is a matter of implementing this interface, not editing a type switch.

type InfiniteRange added in v1.2.0

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

InfiniteRange is a lazy infinite integer sequence.

func NewInfiniteRange added in v1.2.0

func NewInfiniteRange(start, step int) *InfiniteRange

func (*InfiniteRange) ChunkedFirst added in v1.9.0

func (r *InfiniteRange) ChunkedFirst() IChunk

InfiniteRange's chunked view emits a full rangeChunkSize chunk every time and never returns nil from ChunkedNext/More — consumers must short-circuit.

func (*InfiniteRange) ChunkedMore added in v1.9.0

func (r *InfiniteRange) ChunkedMore() Seq

func (*InfiniteRange) ChunkedNext added in v1.9.0

func (r *InfiniteRange) ChunkedNext() Seq

func (*InfiniteRange) Cons added in v1.2.0

func (r *InfiniteRange) Cons(val Value) Seq

func (*InfiniteRange) First added in v1.2.0

func (r *InfiniteRange) First() Value

func (*InfiniteRange) More added in v1.2.0

func (r *InfiniteRange) More() Seq

func (*InfiniteRange) Next added in v1.2.0

func (r *InfiniteRange) Next() Seq

func (*InfiniteRange) Seq added in v1.2.0

func (r *InfiniteRange) Seq() Seq

func (*InfiniteRange) String added in v1.2.0

func (r *InfiniteRange) String() string

func (*InfiniteRange) Type added in v1.2.0

func (r *InfiniteRange) Type() ValueType

func (*InfiniteRange) Unbox added in v1.2.0

func (r *InfiniteRange) Unbox() any

type Instant added in v1.8.0

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

Instant wraps a time.Time, normalised to UTC at millisecond precision.

Precision is millisecond to match Clojure JVM (java.util.Date) and ClojureScript (js/Date), so values round-trip cleanly through any Clojure tool reading the same RFC3339 string.

func NewInstant added in v1.8.0

func NewInstant(t time.Time) *Instant

NewInstant constructs an Instant from a time.Time, normalising to UTC at millisecond precision.

The caller is responsible for ensuring the year is in 0..9999 — values outside that range will not round-trip through Val()/ParseInstant and will silently break AOT bytecode serialisation. The only value-system entry point that takes a host time.Time is InstantType.Box, which enforces this bound; direct Go callers must do the same.

func ParseInstant added in v1.8.0

func ParseInstant(s string) *Instant

ParseInstant parses an RFC3339 (or RFC3339Nano) timestamp. Returns nil if invalid. Sub-millisecond precision in the input is truncated.

func (*Instant) Equals added in v1.8.0

func (i *Instant) Equals(other Value) bool

Equals compares by epoch milliseconds. After UTC+millis normalisation in the constructors this matches t.Equal, but expressing it directly in terms of UnixMilli decouples value identity from time.Time internals (e.g. any monotonic clock reading).

func (*Instant) Hash added in v1.8.0

func (i *Instant) Hash() uint32

Hash implements Hashable. Grounded in epoch milliseconds (the actual value) rather than the formatted string so hash identity is independent of presentation choices (RFC3339Nano trims trailing zeros, etc.).

func (*Instant) String added in v1.8.0

func (i *Instant) String() string

func (*Instant) Time added in v1.8.0

func (i *Instant) Time() time.Time

Time returns the underlying time.Time (UTC, millisecond precision).

func (*Instant) Type added in v1.8.0

func (i *Instant) Type() ValueType

func (*Instant) Unbox added in v1.8.0

func (i *Instant) Unbox() any

func (*Instant) Val added in v1.8.0

func (i *Instant) Val() string

Val returns the canonical RFC3339Nano string form (no #inst wrapping).

type Int

type Int int

Int is boxed int

func (Int) Hash

func (l Int) Hash() uint32

Hash implements Hashable.

func (Int) String

func (l Int) String() string

func (Int) Type

func (l Int) Type() ValueType

Type implements Value

func (Int) Unbox

func (l Int) Unbox() any

Unbox implements Unbox

type Iterate

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

Iterate is a Value whose only value is Iterate

func NewIterate

func NewIterate(f Fn, state Value) *Iterate

func (*Iterate) Cons

func (n *Iterate) Cons(value Value) Seq

func (*Iterate) First

func (n *Iterate) First() Value

func (*Iterate) More

func (n *Iterate) More() Seq

func (*Iterate) Next

func (n *Iterate) Next() Seq

func (*Iterate) Seq

func (n *Iterate) Seq() Seq

func (*Iterate) String

func (n *Iterate) String() string

func (*Iterate) Type

func (n *Iterate) Type() ValueType

Type implements Value

func (*Iterate) Unbox

func (n *Iterate) Unbox() any

Unbox implements Value

type Keyed

type Keyed interface {
	Value
	Contains(Value) Boolean
}

type Keyword

type Keyword string

Keyword is boxed int

func (Keyword) Arity

func (l Keyword) Arity() int

func (Keyword) Hash

func (l Keyword) Hash() uint32

Hash implements Hashable for fast map lookups.

func (Keyword) Invoke

func (l Keyword) Invoke(pargs []Value) (Value, error)

func (Keyword) Name

func (l Keyword) Name() Value

func (Keyword) Namespace

func (l Keyword) Namespace() Value

func (Keyword) Namespaced

func (l Keyword) Namespaced() (Value, Value)

func (Keyword) NamespacedRaw added in v1.12.0

func (l Keyword) NamespacedRaw() (ns Keyword, name Keyword, hasNS bool)

func (Keyword) String

func (l Keyword) String() string

func (Keyword) Type

func (l Keyword) Type() ValueType

Type implements Value

func (Keyword) Unbox

func (l Keyword) Unbox() any

Unbox implements Unbox

type KeywordLookup added in v1.12.0

type KeywordLookup interface {
	ValueAtKeyword(k Keyword) Value
	ValueAtKeywordOr(k Keyword, dflt Value) Value
}

KeywordLookup is an optional fast path for keyword-keyed lookup that avoids boxing the Keyword into a Value interface (type Keyword string boxes on interface conversion — a heap alloc). Keyword.Invoke prefers it when present.

type LazySeq

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

LazySeq delays computation of a sequence until first/next is called. This is the foundation for lazy operations like map, filter, etc.

func NewLazySeq

func NewLazySeq(fn Fn) *LazySeq

func (*LazySeq) Conj

func (l *LazySeq) Conj(val Value) Collection

func (*LazySeq) Cons

func (l *LazySeq) Cons(val Value) Seq

func (*LazySeq) Count

func (l *LazySeq) Count() Value

func (*LazySeq) Empty

func (l *LazySeq) Empty() Collection

func (*LazySeq) First

func (l *LazySeq) First() Value

func (*LazySeq) Hash added in v1.8.0

func (l *LazySeq) Hash() uint32

Hash implements Hashable. Resolves the lazy chain and hashes as an ordered collection, matching *List/*Cons so the three sequence representations equate in sets/maps. An empty resolution (Go nil from a (lazy-seq nil)) must hash the same as EmptyList — Resolve() returns nil but EmptyList.Hash iterates once over its sentinel element, so we substitute EmptyList here.

func (*LazySeq) IsRealized added in v1.8.0

func (l *LazySeq) IsRealized() bool

func (*LazySeq) More

func (l *LazySeq) More() Seq

func (*LazySeq) Next

func (l *LazySeq) Next() Seq

func (*LazySeq) RawCount

func (l *LazySeq) RawCount() int

func (*LazySeq) Resolve

func (l *LazySeq) Resolve() Seq

Resolve returns the fully realized non-LazySeq inner seq. Iteratively unwraps nested LazySeqs without accumulating Go stack.

func (*LazySeq) Seq

func (l *LazySeq) Seq() Seq

func (*LazySeq) String

func (l *LazySeq) String() string

func (*LazySeq) Type

func (l *LazySeq) Type() ValueType

func (*LazySeq) Unbox

func (l *LazySeq) Unbox() any

func (*LazySeq) ValueAt

func (l *LazySeq) ValueAt(key Value) Value

func (*LazySeq) ValueAtOr

func (l *LazySeq) ValueAtOr(key Value, notFound Value) Value

type List

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

List is boxed singly linked list that can hold other Values.

var EmptyList *List = &List{count: 0}

EmptyList is an empty List

func (*List) Conj

func (l *List) Conj(value Value) Collection

func (*List) Cons

func (l *List) Cons(val Value) Seq

Cons implements Seq

func (*List) Count

func (l *List) Count() Value

Count implements Collection

func (*List) Empty

func (l *List) Empty() Collection

Empty implements Collection

func (*List) First

func (l *List) First() Value

First implements Seq

func (*List) Hash

func (l *List) Hash() uint32

Hash implements Hashable. Cached after first computation.

func (*List) Meta

func (l *List) Meta() Value

Meta implements IMeta.

func (*List) More

func (l *List) More() Seq

More implements Seq

func (*List) Next

func (l *List) Next() Seq

Next implements Seq

func (*List) RawCount

func (l *List) RawCount() int

func (*List) Seq

func (l *List) Seq() Seq

func (*List) String

func (l *List) String() string

func (*List) Type

func (l *List) Type() ValueType

Type implements Value

func (*List) Unbox

func (l *List) Unbox() any

Unbox implements Value

func (*List) ValueAt

func (l *List) ValueAt(key Value) Value

func (*List) ValueAtOr

func (l *List) ValueAtOr(key Value, dflt Value) Value

func (*List) WithMeta

func (l *List) WithMeta(m Value) Value

WithMeta implements IMeta.

type LocalVar added in v1.10.0

type LocalVar struct {
	Slot int
	Name string
}

CodeChunk holds bytecode and provides facilities for reading and writing it LocalVar is a debug-info entry mapping a stack slot to the original source name of a local binding (let/loop binding, fn parameter, catch binding). Carried so crash traces from bundle-loaded code (e.g. under WASM) can name local variables, not just slots.

type Lookup

type Lookup interface {
	Value
	ValueAt(Value) Value
	ValueAtOr(Value, Value) Value
}

type LookupStats added in v1.11.1

type LookupStats struct {
	NamespacedCalls uint64
	LookupCalls     uint64
	NamespacedBySym map[string]uint64
	LookupByNS      map[string]uint64
	LookupByNSSym   map[string]uint64
}

func SnapshotLookupStats added in v1.11.1

func SnapshotLookupStats() LookupStats

func (LookupStats) Summary added in v1.11.1

func (s LookupStats) Summary() string

type Map

type Map map[Value]Value

Map is boxed singly linked list that can hold other Values.

func (Map) Arity

func (l Map) Arity() int

func (Map) Assoc

func (l Map) Assoc(k Value, v Value) Associative

func (Map) Conj

func (l Map) Conj(value Value) Collection

func (Map) Cons

func (l Map) Cons(val Value) Seq

Cons implements Seq

func (Map) Contains

func (l Map) Contains(value Value) Boolean

func (Map) Count

func (l Map) Count() Value

Count implements Collection

func (Map) Dissoc

func (l Map) Dissoc(k Value) Associative

func (Map) Empty

func (l Map) Empty() Collection

Empty implements Collection

func (Map) First

func (l Map) First() Value

First implements Seq

func (Map) Invoke

func (l Map) Invoke(pargs []Value) (Value, error)

func (Map) More

func (l Map) More() Seq

More implements Seq

func (Map) Next

func (l Map) Next() Seq

Next implements Seq

func (Map) RawCount

func (l Map) RawCount() int

func (Map) Seq

func (l Map) Seq() Seq

func (Map) String

func (l Map) String() string

func (Map) Type

func (l Map) Type() ValueType

Type implements Value

func (Map) Unbox

func (l Map) Unbox() any

Unbox implements Value

func (Map) ValueAt

func (l Map) ValueAt(key Value) Value

func (Map) ValueAtOr

func (l Map) ValueAtOr(key Value, dflt Value) Value

type MapEntry

type MapEntry struct {
	Key   Value
	Value Value
}

MapEntry is a key-value pair.

func (MapEntry) Conj added in v1.6.0

func (e MapEntry) Conj(v Value) Collection

func (MapEntry) Cons added in v1.6.0

func (e MapEntry) Cons(v Value) Seq

func (MapEntry) Contains added in v1.12.0

func (e MapEntry) Contains(k Value) Boolean

func (MapEntry) Count added in v1.6.0

func (e MapEntry) Count() Value

func (MapEntry) Empty added in v1.6.0

func (e MapEntry) Empty() Collection

func (MapEntry) Equals added in v1.6.0

func (e MapEntry) Equals(other Value) bool

func (MapEntry) First added in v1.6.0

func (e MapEntry) First() Value

func (MapEntry) Hash added in v1.6.0

func (e MapEntry) Hash() uint32

func (MapEntry) More added in v1.6.0

func (e MapEntry) More() Seq

func (MapEntry) Next added in v1.6.0

func (e MapEntry) Next() Seq

func (MapEntry) RawCount added in v1.6.0

func (e MapEntry) RawCount() int

func (MapEntry) Seq added in v1.6.0

func (e MapEntry) Seq() Seq

func (MapEntry) String added in v1.6.0

func (e MapEntry) String() string

func (MapEntry) Type added in v1.6.0

func (e MapEntry) Type() ValueType

func (MapEntry) Unbox added in v1.6.0

func (e MapEntry) Unbox() any

func (MapEntry) ValueAt added in v1.6.0

func (e MapEntry) ValueAt(k Value) Value

func (MapEntry) ValueAtOr added in v1.6.0

func (e MapEntry) ValueAtOr(k Value, dflt Value) Value

type MapSeq

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

MapSeq is a lightweight seq view over a Map's entries

func (*MapSeq) Conj

func (s *MapSeq) Conj(val Value) Collection

func (*MapSeq) Cons

func (s *MapSeq) Cons(val Value) Seq

func (*MapSeq) Count

func (s *MapSeq) Count() Value

func (*MapSeq) Empty

func (s *MapSeq) Empty() Collection

func (*MapSeq) First

func (s *MapSeq) First() Value

func (*MapSeq) More

func (s *MapSeq) More() Seq

func (*MapSeq) Next

func (s *MapSeq) Next() Seq

func (*MapSeq) RawCount

func (s *MapSeq) RawCount() int

func (*MapSeq) Seq

func (s *MapSeq) Seq() Seq

func (*MapSeq) String

func (s *MapSeq) String() string

func (*MapSeq) Type

func (s *MapSeq) Type() ValueType

func (*MapSeq) Unbox

func (s *MapSeq) Unbox() any

type MetaFn added in v1.12.0

type MetaFn struct {
	*MetaValue[Fn]
}

MetaFn adds the Fn surface to the generic metadata decorator. ExecContext unwraps it before dispatch so closures and context-aware natives still receive the caller's dynamic context.

func NewMetaFn added in v1.12.0

func NewMetaFn(fn Fn, meta Value) *MetaFn

func (*MetaFn) Arity added in v1.12.0

func (f *MetaFn) Arity() int

func (*MetaFn) Invoke added in v1.12.0

func (f *MetaFn) Invoke(args []Value) (Value, error)

func (*MetaFn) WithMeta added in v1.12.0

func (f *MetaFn) WithMeta(meta Value) Value

type MetaValue added in v1.12.0

type MetaValue[T Value] struct {
	// contains filtered or unexported fields
}

MetaValue decorates any Value with metadata while delegating its ordinary Value behavior to the wrapped value.

func NewMetaValue added in v1.12.0

func NewMetaValue[T Value](wrapped T, meta Value) *MetaValue[T]

func (*MetaValue[T]) Meta added in v1.12.0

func (m *MetaValue[T]) Meta() Value

func (*MetaValue[T]) String added in v1.12.0

func (m *MetaValue[T]) String() string

func (*MetaValue[T]) Type added in v1.12.0

func (m *MetaValue[T]) Type() ValueType

func (*MetaValue[T]) Unbox added in v1.12.0

func (m *MetaValue[T]) Unbox() any

func (*MetaValue[T]) WithMeta added in v1.12.0

func (m *MetaValue[T]) WithMeta(v Value) Value

func (*MetaValue[T]) Wrapped added in v1.12.0

func (m *MetaValue[T]) Wrapped() T

type MultiArityFn

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

func MakeMultiArity added in v1.9.0

func MakeMultiArity(fns []Value) (*MultiArityFn, error)

func (*MultiArityFn) Arity

func (l *MultiArityFn) Arity() int

func (*MultiArityFn) Invoke

func (l *MultiArityFn) Invoke(pargs []Value) (Value, error)

func (*MultiArityFn) MakeClosure added in v1.9.0

func (l *MultiArityFn) MakeClosure() Fn

func (*MultiArityFn) Meta added in v1.12.0

func (l *MultiArityFn) Meta() Value

Meta implements IMeta.

func (*MultiArityFn) String

func (l *MultiArityFn) String() string

func (*MultiArityFn) Type

func (l *MultiArityFn) Type() ValueType

func (*MultiArityFn) Unbox

func (l *MultiArityFn) Unbox() any

Unbox implements Unbox

func (*MultiArityFn) WithMeta added in v1.12.0

func (l *MultiArityFn) WithMeta(m Value) Value

WithMeta implements IMeta. Returns a copy carrying m; the arity variants are immutable at call time, so sharing them across the copy is safe.

type MultiFn

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

MultiFn implements Clojure-style multimethods. It holds a dispatch function and a map of dispatch-value → method.

func NewMultiFn

func NewMultiFn(name string, dispatchFn Fn, defaultVal Value) *MultiFn

func (*MultiFn) AddMethod

func (m *MultiFn) AddMethod(dispatchVal Value, method Fn) *MultiFn

AddMethod registers an implementation for a dispatch value.

func (*MultiFn) Arity

func (m *MultiFn) Arity() int

Arity returns -1 (variadic — arity depends on the method).

func (*MultiFn) FreezeNative added in v1.11.0

func (m *MultiFn) FreezeNative()

FreezeNative marks this MultiFn as the captured baseline for generated native dispatch arms. Done once, in place, at namespace-load completion (rt.ApplyGoOverrides) — the var still points at this exact pointer, and any later AddMethod/RemoveMethod yields a fresh, unfrozen MultiFn.

func (*MultiFn) GetMethod added in v1.12.0

func (m *MultiFn) GetMethod(dv Value) Value

GetMethod returns the method fn that dispatch value dv would select — the exact match, else the default method, else NIL. Mirrors invokeIn's method selection (let-go multimethods dispatch on exact value + default, not the isa? hierarchy). Backs the core get-method fn.

func (*MultiFn) Invoke

func (m *MultiFn) Invoke(args []Value) (Value, error)

Invoke calls the dispatch function, looks up the method, and calls it.

func (*MultiFn) IsNativeFrozen added in v1.11.0

func (m *MultiFn) IsNativeFrozen() bool

IsNativeFrozen reports whether this MultiFn is still the native baseline (no defmethod has replaced it since FreezeNative). The generated type-switch only trusts its baked arms while this holds.

func (*MultiFn) Meta added in v1.12.0

func (m *MultiFn) Meta() Value

Meta implements IMeta.

func (*MultiFn) Methods

func (m *MultiFn) Methods() *PersistentMap

Methods returns the method map.

func (*MultiFn) RemoveMethod

func (m *MultiFn) RemoveMethod(dispatchVal Value) *MultiFn

RemoveMethod unregisters an implementation.

func (*MultiFn) String

func (m *MultiFn) String() string

func (*MultiFn) Type

func (m *MultiFn) Type() ValueType

func (*MultiFn) Unbox

func (m *MultiFn) Unbox() any

func (*MultiFn) WithMeta added in v1.12.0

func (m *MultiFn) WithMeta(meta Value) Value

WithMeta implements IMeta. Returns a copy carrying meta; the dispatch fn and (immutable-persistent) method map are shared. let-go's fn? includes MultiFn, so multimethods round-trip metadata like every other fn? value. The copy keeps frozen=false — a meta'd copy is not the native dispatch baseline.

type Named

type Named interface {
	Value
	Name() Value
	Namespace() Value
}

type Namespace

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

func NewNamespace

func NewNamespace(name string) *Namespace

func (*Namespace) Alias

func (n *Namespace) Alias(alias Symbol, target *Namespace)

Alias creates a symbol alias to another namespace in this namespace.

Collision guard: re-pointing an existing alias at a DIFFERENT namespace is almost always a bug — either two `:as` clauses in one ns picking the same short name for different libs, or (historically) cross-namespace alias-table contamination during dependency loading. Rather than letting the last writer silently win, warn so the conflict is visible. Re-aliasing to the SAME target (idempotent ns reload) and first-time aliasing are silent.

func (*Namespace) Def

func (n *Namespace) Def(name string, val Value) *Var

func (*Namespace) DefStub added in v1.8.0

func (n *Namespace) DefStub(name string) *Var

DefStub interns an UNBOUND var (no root) without triggering the warn-on-shadow check. Intended for bundle decoders that pre-populate var references before the namespace's own chunk runs (which Defs the ones that have an init). Leaving the root unset is load-bearing: a no-init (def x) / (declare x) emits only OP_LOAD_CONST, so the stub is the var that survives into the namespace, and it must report (bound? (var x)) == false to match the source-compiled path (LookupOrAdd). A NIL root would make precompiled / LGB-loaded code wrongly appear bound, breaking def/declare promise semantics. Do NOT use DefStub to intentionally suppress warnings for new code; use Namespace.Exclude (via :refer-clojure :exclude) instead.

func (*Namespace) Exclude added in v1.8.0

func (n *Namespace) Exclude(name string)

Exclude marks a symbol as excluded from clojure.core auto-refer. Called from the ns macro for :refer-clojure :exclude [...].

func (*Namespace) ImportVar

func (n *Namespace) ImportVar(from *Namespace, name Symbol, alias Symbol) bool

ImportVar links a var from another namespace into this namespace under the given alias. Returns true when the var exists and is not private.

func (*Namespace) IsExcluded added in v1.8.0

func (n *Namespace) IsExcluded(name Symbol) bool

IsExcluded reports whether the symbol is in the exclude set.

func (*Namespace) Lookup

func (n *Namespace) Lookup(symbol Symbol) Value

func (*Namespace) LookupLocal added in v1.3.0

func (n *Namespace) LookupLocal(symbol Symbol) *Var

LookupLocal checks only the namespace's own registry, not refers or aliases.

func (*Namespace) LookupOrAdd

func (n *Namespace) LookupOrAdd(symbol Symbol) Value

func (*Namespace) Name

func (n *Namespace) Name() string

func (*Namespace) PublicVars added in v1.12.0

func (n *Namespace) PublicVars() map[Symbol]*Var

PublicVars snapshots the namespace's own non-private interned vars, keyed by their unqualified symbol. Backs the ns-publics core fn. isPrivate is a plain field read, so filtering under the read lock introduces no lock-order risk.

func (*Namespace) Refer

func (n *Namespace) Refer(ns *Namespace, alias string, all bool)

func (*Namespace) ReferList

func (n *Namespace) ReferList(ns *Namespace, symbols []Symbol)

ReferList refers only selected symbols from the given namespace into this namespace.

func (*Namespace) RegistrySize

func (n *Namespace) RegistrySize() int

func (*Namespace) ResolveAlias

func (n *Namespace) ResolveAlias(alias Symbol) *Namespace

ResolveAlias returns the namespace for the given alias, or nil.

func (*Namespace) String

func (n *Namespace) String() string

func (*Namespace) Type

func (n *Namespace) Type() ValueType

func (*Namespace) Unbox

func (n *Namespace) Unbox() any

Unbox implements Unbox

type NativeFn

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

func NewCtxNativeFn added in v1.11.0

func NewCtxNativeFn(name string, fn func(ec *ExecContext, args []Value) (Value, error)) *NativeFn

NewCtxNativeFn builds a context-aware native builtin. Its plain Invoke resolves against the root context (host/reflection callers); ec.Invoke routes the real context in.

func (*NativeFn) Arity

func (l *NativeFn) Arity() int

func (*NativeFn) HasCtx added in v1.11.0

func (l *NativeFn) HasCtx() bool

HasCtx reports whether this native takes an ExecContext.

func (*NativeFn) Invoke

func (l *NativeFn) Invoke(args []Value) (ret Value, err error)

func (*NativeFn) Meta added in v1.12.0

func (l *NativeFn) Meta() Value

Meta implements IMeta.

func (*NativeFn) SetName

func (l *NativeFn) SetName(n string)

func (*NativeFn) String

func (l *NativeFn) String() string

func (*NativeFn) Type

func (l *NativeFn) Type() ValueType

func (*NativeFn) Unbox

func (l *NativeFn) Unbox() any

Unbox implements Unbox

func (*NativeFn) WithArity

func (l *NativeFn) WithArity(arity int, variadric bool) *NativeFn

func (*NativeFn) WithMeta added in v1.12.0

func (l *NativeFn) WithMeta(m Value) Value

WithMeta implements IMeta. Returns a copy carrying m. Native builtins are shared singletons (e.g. one core/+), so this MUST copy rather than mutate; the wrapped fn/proxies are immutable, so sharing them across the copy is safe.

type Nil

type Nil struct{}

Nil is a Value whose only value is Nil

var NIL *Nil = NilType.zero

NIL is the only value of NilType (and only instance of NilValue)

func (*Nil) Assoc

func (n *Nil) Assoc(k Value, v Value) Associative

func (*Nil) Conj

func (n *Nil) Conj(value Value) Collection

func (*Nil) Cons

func (n *Nil) Cons(value Value) Seq

func (*Nil) Count

func (n *Nil) Count() Value

func (*Nil) Dissoc

func (n *Nil) Dissoc(k Value) Associative

func (*Nil) Empty

func (n *Nil) Empty() Collection

func (*Nil) First

func (n *Nil) First() Value

func (*Nil) More

func (n *Nil) More() Seq

func (*Nil) Next

func (n *Nil) Next() Seq

func (*Nil) RawCount

func (n *Nil) RawCount() int

func (*Nil) Seq

func (n *Nil) Seq() Seq

func (*Nil) String

func (n *Nil) String() string

func (*Nil) Type

func (n *Nil) Type() ValueType

Type implements Value

func (*Nil) Unbox

func (n *Nil) Unbox() any

Unbox implements Value

type PairSample added in v1.9.0

type PairSample struct {
	Prev, Curr uint8
	PrevName   string
	CurrName   string
	Count      uint64
}

PairSample is one entry in a pair-count snapshot.

func PairSnapshot added in v1.9.0

func PairSnapshot() []PairSample

PairSnapshot returns the current per-pair counts, sorted desc. Only entries with non-zero counts are returned.

type PersistentMap

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

PersistentMap is an immutable hash-array mapped trie (HAMT).

func MapFromGoMap

func MapFromGoMap(m map[Value]Value) *PersistentMap

MapFromGoMap converts a Go map[Value]Value to a *PersistentMap.

func NewArrayMap added in v1.8.0

func NewArrayMap(kvs []Value) *PersistentMap

NewArrayMap creates a PersistentMap from an alternating key-value slice. Orderless by design: Clojure map order is an emergent array-map implementation detail (dropped past 8 entries), not a guarantee — let-go treats maps as unordered (cf. Go/Abseil map-iteration randomization). Order-dependent suite tests get :lg reader-cond branches.

func NewPersistentMap

func NewPersistentMap(kvs []Value) *PersistentMap

NewPersistentMap creates a PersistentMap from an alternating key-value slice.

func (*PersistentMap) Arity

func (m *PersistentMap) Arity() int

func (*PersistentMap) Assoc

func (m *PersistentMap) Assoc(key Value, val Value) Associative

func (*PersistentMap) Conj

func (m *PersistentMap) Conj(value Value) Collection

func (*PersistentMap) Contains

func (m *PersistentMap) Contains(key Value) Boolean

func (*PersistentMap) Count

func (m *PersistentMap) Count() Value

func (*PersistentMap) Dissoc

func (m *PersistentMap) Dissoc(key Value) Associative

func (*PersistentMap) Empty

func (m *PersistentMap) Empty() Collection

func (*PersistentMap) Equals

func (m *PersistentMap) Equals(other Value) bool

func (*PersistentMap) Hash

func (m *PersistentMap) Hash() uint32

Hash implements Hashable. Cached after first computation. Uses unordered hashing (order-independent) since maps are unordered.

func (*PersistentMap) Invoke

func (m *PersistentMap) Invoke(pargs []Value) (Value, error)

func (*PersistentMap) Meta

func (m *PersistentMap) Meta() Value

Meta implements IMeta.

func (*PersistentMap) RawCount

func (m *PersistentMap) RawCount() int

func (*PersistentMap) Seq

func (m *PersistentMap) Seq() Seq

func (*PersistentMap) String

func (m *PersistentMap) String() string

func (*PersistentMap) Type

func (m *PersistentMap) Type() ValueType

func (*PersistentMap) Unbox

func (m *PersistentMap) Unbox() any

func (*PersistentMap) ValueAt

func (m *PersistentMap) ValueAt(key Value) Value

func (*PersistentMap) ValueAtKeyword added in v1.12.0

func (m *PersistentMap) ValueAtKeyword(k Keyword) Value

func (*PersistentMap) ValueAtKeywordOr added in v1.12.0

func (m *PersistentMap) ValueAtKeywordOr(k Keyword, dflt Value) Value

func (*PersistentMap) ValueAtOr

func (m *PersistentMap) ValueAtOr(key Value, dflt Value) Value

func (*PersistentMap) WithMeta

func (m *PersistentMap) WithMeta(meta Value) Value

WithMeta implements IMeta.

type PersistentQueue added in v1.12.0

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

PersistentQueue is an immutable FIFO queue. The empty queue has front == nil.

var EmptyPersistentQueue *PersistentQueue = &PersistentQueue{}

EmptyPersistentQueue is the canonical empty queue (clojure.lang.PersistentQueue/EMPTY).

func (*PersistentQueue) Conj added in v1.12.0

func (q *PersistentQueue) Conj(value Value) Collection

Conj implements Collection — appends to the rear (Clojure enqueue semantics). The very first element seeds the front instead, so peek always has somewhere to read from.

func (*PersistentQueue) Count added in v1.12.0

func (q *PersistentQueue) Count() Value

func (*PersistentQueue) Empty added in v1.12.0

func (q *PersistentQueue) Empty() Collection

Empty implements Collection.

func (*PersistentQueue) Equals added in v1.12.0

func (q *PersistentQueue) Equals(other Value) bool

Equals implements value equality — another queue with the same elements in the same FIFO order.

func (*PersistentQueue) Hash added in v1.12.0

func (q *PersistentQueue) Hash() uint32

Hash implements Hashable — order-sensitive, over the FIFO sequence.

func (*PersistentQueue) Meta added in v1.12.0

func (q *PersistentQueue) Meta() Value

Meta / WithMeta implement IMeta.

func (*PersistentQueue) Peek added in v1.12.0

func (q *PersistentQueue) Peek() Value

Peek returns the front element, or NIL when empty.

func (*PersistentQueue) Pop added in v1.12.0

func (q *PersistentQueue) Pop() *PersistentQueue

Pop returns the queue without its front element. Popping the empty queue returns it unchanged (matching Clojure, which does not throw here). When the front seq drains, the rear is promoted to become the new front in FIFO order.

func (*PersistentQueue) RawCount added in v1.12.0

func (q *PersistentQueue) RawCount() int

RawCount / Count implement Counted.

func (*PersistentQueue) Seq added in v1.12.0

func (q *PersistentQueue) Seq() Seq

Seq implements Sequable — front elements first, then the rear in FIFO order. Returns EmptyList for the empty queue (the seq builtin maps that to nil).

func (*PersistentQueue) String added in v1.12.0

func (q *PersistentQueue) String() string

func (*PersistentQueue) Type added in v1.12.0

func (q *PersistentQueue) Type() ValueType

Type implements Value.

func (*PersistentQueue) Unbox added in v1.12.0

func (q *PersistentQueue) Unbox() any

Unbox implements Value — a flat []Value in FIFO order.

func (*PersistentQueue) WithMeta added in v1.12.0

func (q *PersistentQueue) WithMeta(m Value) Value

type PersistentSet

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

PersistentSet is an immutable set backed by a PersistentMap. Each element is stored as a key mapping to itself (like Clojure's PersistentHashSet).

func NewPersistentSet

func NewPersistentSet(vals []Value) *PersistentSet

func (*PersistentSet) Arity

func (s *PersistentSet) Arity() int

func (*PersistentSet) Conj

func (s *PersistentSet) Conj(value Value) Collection

func (*PersistentSet) Cons

func (s *PersistentSet) Cons(val Value) Seq

func (*PersistentSet) Contains

func (s *PersistentSet) Contains(value Value) Boolean

func (*PersistentSet) Count

func (s *PersistentSet) Count() Value

func (*PersistentSet) Disj

func (s *PersistentSet) Disj(value Value) *PersistentSet

func (*PersistentSet) Empty

func (s *PersistentSet) Empty() Collection

func (*PersistentSet) First

func (s *PersistentSet) First() Value

func (*PersistentSet) Hash

func (s *PersistentSet) Hash() uint32

func (*PersistentSet) Invoke

func (s *PersistentSet) Invoke(pargs []Value) (Value, error)

func (*PersistentSet) Meta

func (s *PersistentSet) Meta() Value

func (*PersistentSet) More

func (s *PersistentSet) More() Seq

func (*PersistentSet) Next

func (s *PersistentSet) Next() Seq

func (*PersistentSet) RawCount

func (s *PersistentSet) RawCount() int

func (*PersistentSet) Seq

func (s *PersistentSet) Seq() Seq

func (*PersistentSet) String

func (s *PersistentSet) String() string

func (*PersistentSet) Type

func (s *PersistentSet) Type() ValueType

func (*PersistentSet) Unbox

func (s *PersistentSet) Unbox() any

func (*PersistentSet) ValueAt added in v1.5.0

func (s *PersistentSet) ValueAt(key Value) Value

func (*PersistentSet) ValueAtOr added in v1.5.0

func (s *PersistentSet) ValueAtOr(key Value, dflt Value) Value

func (*PersistentSet) WithMeta

func (s *PersistentSet) WithMeta(m Value) Value

type PersistentVector

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

PersistentVector is a persistent vector implementation using a bit-partitioned trie

func (PersistentVector) Arity

func (v PersistentVector) Arity() int

Arity implements IFn

func (PersistentVector) Assoc

func (v PersistentVector) Assoc(key Value, val Value) Associative

Assoc implements Associative

func (PersistentVector) Conj

func (v PersistentVector) Conj(val Value) Collection

Conj implements Collection

func (PersistentVector) Contains

func (v PersistentVector) Contains(key Value) Boolean

Contains implements Associative

func (PersistentVector) Count

func (v PersistentVector) Count() Value

Count implements Collection

func (PersistentVector) Dissoc

func (v PersistentVector) Dissoc(key Value) Associative

Dissoc implements Associative

func (PersistentVector) Empty

func (v PersistentVector) Empty() Collection

Empty implements Collection

func (PersistentVector) Equals

func (v PersistentVector) Equals(other Value) bool

Equals implements value equality for PersistentVector

func (PersistentVector) Hash

func (v PersistentVector) Hash() uint32

Hash implements Hashable. Computed from elements.

func (PersistentVector) IdentityKey added in v1.12.0

func (v PersistentVector) IdentityKey() uintptr

IdentityKey returns an opaque key for the vector's private identity token. A zero-value PersistentVector has no token and returns zero.

func (PersistentVector) Invoke

func (v PersistentVector) Invoke(args []Value) (Value, error)

Invoke implements IFn

func (PersistentVector) Meta

func (v PersistentVector) Meta() Value

Meta implements IMeta.

func (PersistentVector) Nth added in v1.11.0

func (v PersistentVector) Nth(i int) Value

Nth implements Indexed: positional access by integer index.

func (PersistentVector) Pop added in v1.11.0

Pop returns a new vector with the last element removed, in O(1) amortized time (mirrors Clojure's PersistentVector.pop). The previous behavior — the `pop` builtin doing Unbox()+NewPersistentVector(all-but-last) — was O(n) per call, which made vector-as-stack uses (e.g. the typeinfer worklist drain via peek/pop) O(n^2) and a major allocation source. Returns the empty vector for count <= 1; callers that must reject popping an empty vector check count first.

func (PersistentVector) RawCount

func (v PersistentVector) RawCount() int

func (PersistentVector) SameIdentity added in v1.12.0

func (v PersistentVector) SameIdentity(other PersistentVector) bool

SameIdentity reports whether two PersistentVector values are copies of the same logical vector. The token itself remains private to the vm package.

func (PersistentVector) Seq

func (v PersistentVector) Seq() Seq

Modify PersistentVector's Seq method:

func (PersistentVector) String

func (v PersistentVector) String() string

String implements Value

func (PersistentVector) Type

func (v PersistentVector) Type() ValueType

Type implements Value

func (PersistentVector) Unbox

func (v PersistentVector) Unbox() any

Unbox implements Value

func (PersistentVector) ValueAt

func (v PersistentVector) ValueAt(key Value) Value

ValueAt implements Associative

func (PersistentVector) ValueAtOr

func (v PersistentVector) ValueAtOr(key Value, dflt Value) Value

ValueAtOr implements Associative

func (PersistentVector) WithMeta

func (v PersistentVector) WithMeta(m Value) Value

WithMeta implements IMeta.

type PersistentVectorSeq

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

PersistentVectorSeq represents a sequence view of a PersistentVector

func (*PersistentVectorSeq) ChunkedFirst added in v1.9.0

func (s *PersistentVectorSeq) ChunkedFirst() IChunk

ChunkedFirst returns the chunk starting at the current position.

func (*PersistentVectorSeq) ChunkedMore added in v1.9.0

func (s *PersistentVectorSeq) ChunkedMore() Seq

ChunkedMore is like ChunkedNext but returns EmptyList instead of nil at the end, matching Clojure's IChunkedSeq.chunkedMore.

func (*PersistentVectorSeq) ChunkedNext added in v1.9.0

func (s *PersistentVectorSeq) ChunkedNext() Seq

ChunkedNext advances by one whole chunk, returning the seq positioned at the start of the following chunk, or nil at the end.

func (*PersistentVectorSeq) Conj

func (s *PersistentVectorSeq) Conj(val Value) Collection

Conj implements Collection

func (*PersistentVectorSeq) Cons

func (s *PersistentVectorSeq) Cons(val Value) Seq

Cons implements Seq

func (*PersistentVectorSeq) Count

func (s *PersistentVectorSeq) Count() Value

Count implements Collection

func (*PersistentVectorSeq) Empty

func (s *PersistentVectorSeq) Empty() Collection

Empty implements Collection

func (*PersistentVectorSeq) First

func (s *PersistentVectorSeq) First() Value

First implements Seq

func (*PersistentVectorSeq) More

func (s *PersistentVectorSeq) More() Seq

More implements Seq

func (*PersistentVectorSeq) Next

func (s *PersistentVectorSeq) Next() Seq

Next implements Seq

func (*PersistentVectorSeq) Nth added in v1.11.0

func (s *PersistentVectorSeq) Nth(i int) Value

Nth implements Indexed: positional access by integer index.

func (*PersistentVectorSeq) RawCount

func (s *PersistentVectorSeq) RawCount() int

func (*PersistentVectorSeq) String

func (s *PersistentVectorSeq) String() string

String implements Value

func (*PersistentVectorSeq) Type

func (s *PersistentVectorSeq) Type() ValueType

Type implements Value

func (*PersistentVectorSeq) Unbox

func (s *PersistentVectorSeq) Unbox() any

Unbox implements Value

func (*PersistentVectorSeq) ValueAt

func (s *PersistentVectorSeq) ValueAt(key Value) Value

ValueAt implements Lookup for PersistentVectorSeq so that `get` works on seq views.

func (*PersistentVectorSeq) ValueAtOr

func (s *PersistentVectorSeq) ValueAtOr(key Value, dflt Value) Value

ValueAtOr implements Lookup for PersistentVectorSeq.

type ProfileSample added in v1.9.0

type ProfileSample struct {
	Opcode uint8
	Name   string
	Count  uint64
}

ProfileSample is one entry in a profile snapshot.

func ProfileSnapshot added in v1.9.0

func ProfileSnapshot() []ProfileSample

ProfileSnapshot returns the current per-opcode counts, sorted desc. Only entries with non-zero counts are returned.

type Promise

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

Promise is a write-once, read-many synchronization primitive. Created with (promise), written with (deliver p val), read with (deref p). Deref blocks until delivered.

func NewPromise

func NewPromise() *Promise

func (*Promise) Deliver

func (p *Promise) Deliver(val Value) Value

func (*Promise) Deref

func (p *Promise) Deref() Value

func (*Promise) DerefTimeout added in v1.10.0

func (p *Promise) DerefTimeout(timeoutMs int64, timeoutVal Value) Value

DerefTimeout blocks until the promise is delivered or timeoutMs elapses, returning timeoutVal on timeout. Backs Clojure's 3-arg deref for blocking refs (promises/futures).

func (*Promise) IsRealized

func (p *Promise) IsRealized() bool

func (*Promise) String

func (p *Promise) String() string

func (*Promise) Type

func (p *Promise) Type() ValueType

func (*Promise) Unbox

func (p *Promise) Unbox() any

type Protocol

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

Protocol defines a named set of methods with type-based dispatch.

func NewProtocol

func NewProtocol(name string, methods []Symbol) *Protocol

func (*Protocol) Extend

func (p *Protocol) Extend(vt ValueType, implMap *PersistentMap)

Extend adds implementations for a type extended EXACTLY (extend-type on a concrete type). Exact extensions always win: they overwrite a prior TypeUnion-sourced implementation and are never overwritten by a later one — Clojure's exact-type-over-interface dispatch precedence, independent of registration order. implMap is a PersistentMap of {method-keyword → fn}.

func (*Protocol) ExtendNil

func (p *Protocol) ExtendNil(implMap *PersistentMap)

ExtendNil adds implementations for nil.

func (*Protocol) ExtendViaUnion added in v1.12.0

func (p *Protocol) ExtendViaUnion(vt ValueType, implMap *PersistentMap)

ExtendViaUnion adds implementations for one member of a TypeUnion (a compatibility interface like clojure.lang.IPersistentVector fanning out to its concrete vm types). It never clobbers an exact Extend on the same type; unions overwrite only other unions (last union wins, matching Clojure's unspecified interface-vs-interface order).

func (*Protocol) Lookup

func (p *Protocol) Lookup(methodName Symbol, target Value) (Fn, bool)

Lookup finds the implementation of a method for a given value's type.

func (*Protocol) Meta added in v1.10.0

func (p *Protocol) Meta() Value

Meta implements IMeta.

func (*Protocol) Methods

func (p *Protocol) Methods() []Symbol

func (*Protocol) Name

func (p *Protocol) Name() string

func (*Protocol) Satisfies

func (p *Protocol) Satisfies(target Value) bool

Satisfies returns true if the given value's type has an implementation, or a universal default was extended onto Object (AnyType).

func (*Protocol) String

func (p *Protocol) String() string

func (*Protocol) Type

func (p *Protocol) Type() ValueType

func (*Protocol) Unbox

func (p *Protocol) Unbox() any

func (*Protocol) WithMeta added in v1.10.0

func (p *Protocol) WithMeta(m Value) Value

WithMeta implements IMeta. Returns a copy carrying m; dispatch tables are shared with the original (metadata does not affect protocol dispatch).

type ProtocolFn

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

ProtocolFn is a function that dispatches on the first arg's type via a protocol.

func NewProtocolFn

func NewProtocolFn(protocol *Protocol, methodName Symbol) *ProtocolFn

func (*ProtocolFn) Arity

func (f *ProtocolFn) Arity() int

func (*ProtocolFn) Invoke

func (f *ProtocolFn) Invoke(args []Value) (Value, error)

func (*ProtocolFn) Meta added in v1.12.0

func (f *ProtocolFn) Meta() Value

Meta implements IMeta.

func (*ProtocolFn) String

func (f *ProtocolFn) String() string

func (*ProtocolFn) Type

func (f *ProtocolFn) Type() ValueType

func (*ProtocolFn) Unbox

func (f *ProtocolFn) Unbox() any

func (*ProtocolFn) WithMeta added in v1.12.0

func (f *ProtocolFn) WithMeta(m Value) Value

WithMeta implements IMeta. Returns a copy carrying m; the protocol and method name are shared (metadata does not affect dispatch), matching the other FuncType values so a protocol method round-trips metadata like any fn.

type Range

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

Range is a lazy integer sequence with start, end, and step.

func (*Range) Bounds added in v1.12.0

func (l *Range) Bounds() (start, end, step int)

Bounds exposes the range arithmetic (start, end, step) so callers like reduce can iterate a Range with plain arithmetic — no seq or chunk allocation. step is never 0 for a materialized *Range.

func (*Range) ChunkedFirst added in v1.9.0

func (l *Range) ChunkedFirst() IChunk

ChunkedFirst returns up to rangeChunkSize values starting from l.start, stopping at the range's end. The chunk holds materialized Int values; this is one O(chunkSize) allocation per chunk in exchange for amortizing the element-wise allocation overhead of l.Next().

func (*Range) ChunkedMore added in v1.9.0

func (l *Range) ChunkedMore() Seq

func (*Range) ChunkedNext added in v1.9.0

func (l *Range) ChunkedNext() Seq

ChunkedNext returns the range positioned at the element after the current chunk, or nil if the current chunk consumes the whole range.

func (*Range) Conj

func (l *Range) Conj(val Value) Collection

func (*Range) Cons

func (l *Range) Cons(val Value) Seq

Cons implements Seq

func (*Range) Count

func (l *Range) Count() Value

Count implements Collection

func (*Range) Empty

func (l *Range) Empty() Collection

Empty implements Collection

func (*Range) First

func (l *Range) First() Value

First implements Seq

func (*Range) More

func (l *Range) More() Seq

More implements Seq

func (*Range) Next

func (l *Range) Next() Seq

Next implements Seq

func (*Range) Nth added in v1.11.0

func (l *Range) Nth(i int) Value

Nth implements Indexed: positional access by integer index.

func (*Range) RawCount

func (l *Range) RawCount() int

func (*Range) Seq

func (l *Range) Seq() Seq

func (*Range) String

func (l *Range) String() string

func (*Range) Type

func (l *Range) Type() ValueType

Type implements Value

func (*Range) Unbox

func (l *Range) Unbox() any

Unbox implements Value

func (*Range) ValueAt

func (l *Range) ValueAt(key Value) Value

func (*Range) ValueAtOr

func (l *Range) ValueAtOr(key Value, dflt Value) Value

type Ratio added in v1.5.0

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

Ratio wraps *math/big.Rat as a VM value.

func MustRatioFromString added in v1.11.0

func MustRatioFromString(s string) *Ratio

MustRatioFromString builds a Ratio from its "num/den" string form, panicking on an unparseable input. Intended for gogen-emitted constant literals: the source was already validated at read time (and reduced past integer form, so the value is genuinely a Ratio), making the panic unreachable in generated code. Gives a single-value expression form keyed off the value's own String().

func NewRatio added in v1.5.0

func NewRatio(v *big.Rat) *Ratio

func NewRatioFromInts added in v1.5.0

func NewRatioFromInts(num, den int64) *Ratio

func (*Ratio) Equals added in v1.5.0

func (r *Ratio) Equals(other Value) bool

Equals compares two Ratios.

func (*Ratio) GoString added in v1.5.0

func (r *Ratio) GoString() string

func (*Ratio) Hash added in v1.5.0

func (r *Ratio) Hash() uint32

Hash implements Hashable.

func (*Ratio) String added in v1.5.0

func (r *Ratio) String() string

func (*Ratio) ToFloat64 added in v1.5.0

func (r *Ratio) ToFloat64() float64

ToFloat64 converts to float64.

func (*Ratio) Type added in v1.5.0

func (r *Ratio) Type() ValueType

func (*Ratio) Unbox added in v1.5.0

func (r *Ratio) Unbox() any

func (*Ratio) Val added in v1.5.0

func (r *Ratio) Val() *big.Rat

type Receiver

type Receiver interface {
	Value
	InvokeMethod(Symbol, []Value) (Value, error)
}

type Record

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

Record is a value created by defrecord. Fixed fields are stored in a flat array for O(1) access. Extra keys (from assoc) go into an overflow map. All map operations work — seq, keys, count include both fixed and extra fields.

func NewRecord

func NewRecord(rtype *RecordType, data *PersistentMap) *Record

func ToRecord

func ToRecord[T any](v T) *Record

ToRecord converts a Go struct to a Record using its registered mapping. Panics if the struct type is not registered.

func (*Record) Arity

func (r *Record) Arity() int

func (*Record) Assoc

func (r *Record) Assoc(key Value, val Value) Associative

func (*Record) Conj

func (r *Record) Conj(value Value) Collection

func (*Record) Contains

func (r *Record) Contains(key Value) Boolean

func (*Record) Count

func (r *Record) Count() Value

func (*Record) Dissoc

func (r *Record) Dissoc(key Value) Associative

func (*Record) Empty

func (r *Record) Empty() Collection

func (*Record) Equals

func (r *Record) Equals(other Value) bool

func (*Record) Extra added in v1.3.0

func (r *Record) Extra() *PersistentMap

Extra returns the overflow map.

func (*Record) FixedFields added in v1.3.0

func (r *Record) FixedFields() []Value

FixedFields returns the fixed field values.

func (*Record) Hash

func (r *Record) Hash() uint32

func (*Record) Invoke

func (r *Record) Invoke(args []Value) (Value, error)

func (*Record) InvokeMethod

func (r *Record) InvokeMethod(name Symbol, args []Value) (Value, error)

func (*Record) Meta

func (r *Record) Meta() Value

func (*Record) Origin

func (r *Record) Origin() any

Origin returns the original Go struct if this Record was created from one, or nil.

func (*Record) RawCount

func (r *Record) RawCount() int

func (*Record) RecordType

func (r *Record) RecordType() *RecordType

func (*Record) Seq

func (r *Record) Seq() Seq

Seq returns all entries — fixed fields first (in definition order), then extras.

func (*Record) String

func (r *Record) String() string

func (*Record) Type

func (r *Record) Type() ValueType

func (*Record) Unbox

func (r *Record) Unbox() any

func (*Record) ValueAt

func (r *Record) ValueAt(key Value) Value

func (*Record) ValueAtKeyword added in v1.12.0

func (r *Record) ValueAtKeyword(k Keyword) Value

ValueAtKeyword is a box-free fast path for keyword-based record access.

func (*Record) ValueAtKeywordOr added in v1.12.0

func (r *Record) ValueAtKeywordOr(k Keyword, notFound Value) Value

func (*Record) ValueAtOr

func (r *Record) ValueAtOr(key Value, notFound Value) Value

func (*Record) WithMeta

func (r *Record) WithMeta(m Value) Value

type RecordBase added in v1.11.0

type RecordBase struct {
	TypeName string
	// contains filtered or unexported fields
}

RecordBase is embedded by gogen-generated record/op structs so they satisfy vm.Value without per-type boilerplate. Field-specific behavior (field access, equality over fields) is added by the generated struct; this covers the type-identity and stringification contract.

Usage in generated code:

type MyRecord struct {
    RecordBase
    fieldOne Value
    fieldTwo Value
}

The embedding struct automatically satisfies the Value interface.

func (*RecordBase) String added in v1.11.0

func (r *RecordBase) String() string

String returns the TypeName. Required by fmt.Stringer (part of Value interface).

func (*RecordBase) Type added in v1.11.0

func (r *RecordBase) Type() ValueType

Type returns a ValueType representing this record's type. The ValueType is lazily created and cached.

func (*RecordBase) Unbox added in v1.11.0

func (r *RecordBase) Unbox() any

Unbox returns the embedded *RecordBase, NOT the outer embedding struct. Because Unbox is a method on RecordBase promoted onto the embedding type, its receiver is always *RecordBase — Go method promotion cannot recover the outer value. Callers that need the concrete record (e.g. *Square) must hold a typed reference; they cannot recover it through this Value-level Unbox. This is sufficient for the type-identity/stringification contract RecordBase covers; field access on native records goes through the generated struct directly.

type RecordType

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

RecordType is a dynamically-created ValueType for a defrecord. Each defrecord call creates a unique RecordType instance.

func NewRecordType

func NewRecordType(name string, fields []Keyword) *RecordType

func (*RecordType) Box

func (t *RecordType) Box(bare any) (Value, error)

func (*RecordType) Fields

func (t *RecordType) Fields() []Keyword

func (*RecordType) Name

func (t *RecordType) Name() string

func (*RecordType) String

func (t *RecordType) String() string

func (*RecordType) Type

func (t *RecordType) Type() ValueType

func (*RecordType) TypeName added in v1.3.0

func (t *RecordType) TypeName() string

TypeName returns the record type name.

func (*RecordType) Unbox

func (t *RecordType) Unbox() any

type Reduced

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

Reduced wraps a value to signal early termination in reduce/transduce.

func NewReduced

func NewReduced(v Value) *Reduced

func (*Reduced) Deref

func (r *Reduced) Deref() Value

func (*Reduced) String

func (r *Reduced) String() string

func (*Reduced) Type

func (r *Reduced) Type() ValueType

func (*Reduced) Unbox

func (r *Reduced) Unbox() any

type Refer

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

Refer entries are immutable once constructed and inserted, so their fields (ns, all, only) may be read without holding the owning namespace's lock — only the refers MAP itself is mutex-guarded.

type Reference

type Reference interface {
	Deref() Value
}

func AsRef added in v1.10.0

func AsRef(v Value) (Reference, bool)

AsRef returns v as a Reference: directly if it already is one, or — when v's type satisfies the IDeref protocol — wrapped in an adapter that routes Deref to its -deref method. Reports false when v is not derefable.

type Regex

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

Regex is boxed int

A Regex may be shared freely across goroutines/ExecContexts: regex literals compile once at read time into constants visible to all threads, which is safe because every method below is a read-only matching API (Go's regexp is goroutine-safe except mutating config like Longest). Never add a mutating configuration method here without copy-on-write (regexp.Copy).

func MustRegexFromReadable added in v1.12.0

func MustRegexFromReadable(s string) *Regex

MustRegexFromReadable reconstructs a Regex from its readable #"..." form (String()'s output: '#' followed by a Go-quoted pattern). Generated code uses it to rebuild read-time-compiled regex literal constants; the pattern was validated at read time, so failure here indicates a codegen bug.

func (*Regex) FindAllString

func (l *Regex) FindAllString(s string, n int) []string

func (*Regex) FindAllStringSubmatch

func (l *Regex) FindAllStringSubmatch(s string, n int) [][]string

func (*Regex) FindAllStringSubmatchIndex added in v1.12.0

func (l *Regex) FindAllStringSubmatchIndex(s string, n int) [][]int

func (*Regex) FindStringSubmatch

func (l *Regex) FindStringSubmatch(s string) []string

func (*Regex) FindStringSubmatchIndex added in v1.12.0

func (l *Regex) FindStringSubmatchIndex(s string) []int

func (*Regex) Pattern added in v1.3.0

func (l *Regex) Pattern() string

Pattern returns the regex pattern string.

func (*Regex) ReplaceAll

func (l *Regex) ReplaceAll(s string, replacement string) (string, error)

func (*Regex) ReplaceAllFunc added in v1.11.0

func (l *Regex) ReplaceAllFunc(s string, f func(groups []string, present []bool) (string, error)) (string, error)

ReplaceAllFunc replaces every non-overlapping match using f, matching clojure.string/replace with a function replacement. For each match, f receives the submatch groups: groups[0] is the whole match, groups[i] the i-th capture group; present[i] is false for a group that did not participate (so the caller can pass nil, as Clojure's re-groups does).

func (*Regex) ReplaceFirst added in v1.10.0

func (l *Regex) ReplaceFirst(s string, replacement string) (string, error)

ReplaceFirst replaces only the first match, expanding $-group references in the replacement (as ReplaceAll does), matching clojure.string/replace-first.

func (*Regex) ReplaceFirstFunc added in v1.11.0

func (l *Regex) ReplaceFirstFunc(s string, f func(groups []string, present []bool) (string, error)) (string, error)

ReplaceFirstFunc is ReplaceAllFunc limited to the first match, matching clojure.string/replace-first with a function replacement.

func (*Regex) Split added in v1.7.0

func (l *Regex) Split(s string, n int) []string

func (*Regex) String

func (l *Regex) String() string

func (*Regex) Type

func (l *Regex) Type() ValueType

Type implements Value

func (*Regex) Unbox

func (l *Regex) Unbox() any

Unbox implements Unbox

type Repeat

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

Repeat is a Value whose only value is Repeat

func NewRepeat

func NewRepeat(val Value, i int) *Repeat

func (*Repeat) Cons

func (n *Repeat) Cons(value Value) Seq

func (*Repeat) Count

func (n *Repeat) Count() Value

func (*Repeat) First

func (n *Repeat) First() Value

func (*Repeat) More

func (n *Repeat) More() Seq

func (*Repeat) Next

func (n *Repeat) Next() Seq

func (*Repeat) RawCount

func (n *Repeat) RawCount() int

func (*Repeat) Seq

func (n *Repeat) Seq() Seq

func (*Repeat) String

func (n *Repeat) String() string

func (*Repeat) Type

func (n *Repeat) Type() ValueType

Type implements Value

func (*Repeat) Unbox

func (n *Repeat) Unbox() any

Unbox implements Value

type Scope added in v1.9.0

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

func OpenChildEC added in v1.11.0

func OpenChildEC(ec *ExecContext) *Scope

OpenChildEC opens a child of ec's current scope and installs it on ec for a synchronous dynamic extent (the with-scope body, which runs in the same frame, hence the same ec). It returns the child; pair with CloseScoped, which runs the restore that reinstates the previous scope. This is the explicit-context replacement for the old goroutine-id-keyed OpenChild.

func (*Scope) Await added in v1.9.0

func (s *Scope) Await(timeout time.Duration) bool

Await blocks until every goroutine in this scope AND its subtree has exited, or timeout elapses. Returns true if fully drained, false on timeout. A non-positive timeout waits indefinitely.

func (*Scope) Cancel added in v1.9.0

func (s *Scope) Cancel()

Cancel cancels this scope's context — and, by context inheritance, its whole subtree — without installing a fresh one. Terminal: the scope stops accepting new cancellable work. Siblings are unaffected. Does not wait; pair with Await (or use Shutdown).

func (*Scope) CancelAll added in v1.9.0

func (s *Scope) CancelAll()

CancelAll cancels the current context generation and installs a fresh one derived from the parent, so the scope can keep accepting spawns after a drain. This is the "drain and continue" form used by the root between benchmark iterations / at soft shutdown points. Lock-free: the fresh generation is swapped in atomically and we cancel whatever we displaced, so concurrent CancelAlls are safe.

func (*Scope) Child added in v1.9.0

func (s *Scope) Child() *Scope

Child creates a sub-scope whose context is derived from this scope's current context. Cancelling this scope (or any ancestor) cancels the child; cancelling the child leaves this scope and its siblings running.

func (*Scope) Context added in v1.9.0

func (s *Scope) Context() context.Context

Context returns the scope's current cancellation context. Blocking native ops (sleep, channel send/recv, alts!) select on its Done() so they unblock when the scope is cancelled. Lock-free (one atomic load), cheap to call on every channel op.

func (*Scope) Drain added in v1.9.0

func (s *Scope) Drain(timeout time.Duration) bool

Drain cancels the scope's current generation and reinstalls a fresh one (so the scope keeps working), then waits for the displaced work to exit. Used by the root between bench iterations and at soft shutdown.

func (*Scope) Go added in v1.9.0

func (s *Scope) Go(fn func(ctx context.Context))

Go runs fn in a tracked goroutine of THIS scope. fn receives the scope's current context; long-running work should select on ctx.Done() so Cancel/Shutdown/Drain can stop it.

func (*Scope) Live added in v1.9.0

func (s *Scope) Live() int

Live reports how many goroutines are running directly in this scope (not counting sub-scopes). Use LiveTree for the whole subtree.

func (*Scope) LiveTree added in v1.9.0

func (s *Scope) LiveTree() int

LiveTree reports the live goroutine count of this scope and all descendants.

func (*Scope) Shutdown added in v1.9.0

func (s *Scope) Shutdown(timeout time.Duration) bool

Shutdown cancels this scope (terminal, cascades to the subtree) and waits up to timeout for it to drain. The structured-shutdown form for a sub-scope; for the root's drain-and-continue use Drain.

func (*Scope) String added in v1.9.0

func (s *Scope) String() string

func (*Scope) Type added in v1.9.0

func (s *Scope) Type() ValueType

Scope is a Value so it can be handed to Lisp as an opaque handle.

func (*Scope) Unbox added in v1.9.0

func (s *Scope) Unbox() any

type Seq

type Seq interface {
	Value
	Cons(Value) Seq
	First() Value
	More() Seq
	Next() Seq
}

Seq is implemented by all sequence-like values

func ConsChunk added in v1.9.0

func ConsChunk(chunk IChunk, more Seq) Seq

ConsChunk produces the natural seq of `chunk` followed by `more`. If chunk is empty/nil, returns `more` unchanged.

type Sequable

type Sequable interface {
	Value
	Seq() Seq
}

type Set

type Set map[Value]struct{}

Set is boxed singly linked list that can hold other Values.

func (Set) Arity

func (l Set) Arity() int

func (Set) Conj

func (l Set) Conj(value Value) Collection

func (Set) Cons

func (l Set) Cons(val Value) Seq

Cons implements Seq

func (Set) Contains

func (l Set) Contains(value Value) Boolean

func (Set) Count

func (l Set) Count() Value

Count implements Collection

func (Set) Disj

func (l Set) Disj(value Value) Set

func (Set) Empty

func (l Set) Empty() Collection

Empty implements Collection

func (Set) First

func (l Set) First() Value

First implements Seq

func (Set) Hash

func (l Set) Hash() uint32

Hash implements Hashable. Unordered hash over elements.

func (Set) Invoke

func (l Set) Invoke(pargs []Value) (Value, error)

func (Set) Meta

func (l Set) Meta() Value

Meta implements IMeta. Set doesn't store meta, always returns NIL.

func (Set) More

func (l Set) More() Seq

More implements Seq

func (Set) Next

func (l Set) Next() Seq

Next implements Seq

func (Set) RawCount

func (l Set) RawCount() int

func (Set) Seq

func (l Set) Seq() Seq

func (Set) String

func (l Set) String() string

func (Set) Type

func (l Set) Type() ValueType

Type implements Value

func (Set) Unbox

func (l Set) Unbox() any

Unbox implements Value

func (Set) WithMeta

func (l Set) WithMeta(m Value) Value

WithMeta implements IMeta. Returns a SetWithMeta wrapper.

type SetSeq

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

SetSeq is a lightweight seq view over a Set's keys

func (*SetSeq) Conj

func (s *SetSeq) Conj(val Value) Collection

func (*SetSeq) Cons

func (s *SetSeq) Cons(val Value) Seq

func (*SetSeq) Count

func (s *SetSeq) Count() Value

func (*SetSeq) Empty

func (s *SetSeq) Empty() Collection

func (*SetSeq) First

func (s *SetSeq) First() Value

func (*SetSeq) More

func (s *SetSeq) More() Seq

func (*SetSeq) Next

func (s *SetSeq) Next() Seq

func (*SetSeq) RawCount

func (s *SetSeq) RawCount() int

func (*SetSeq) Seq

func (s *SetSeq) Seq() Seq

func (*SetSeq) String

func (s *SetSeq) String() string

func (*SetSeq) Type

func (s *SetSeq) Type() ValueType

func (*SetSeq) Unbox

func (s *SetSeq) Unbox() any

type SetWithMeta

type SetWithMeta struct {
	Set
	// contains filtered or unexported fields
}

SetWithMeta wraps a Set to carry metadata.

func (*SetWithMeta) Conj added in v1.8.0

func (s *SetWithMeta) Conj(value Value) Collection

func (*SetWithMeta) Meta

func (s *SetWithMeta) Meta() Value

func (*SetWithMeta) WithMeta

func (s *SetWithMeta) WithMeta(m Value) Value

type SortedMap added in v1.5.0

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

func NewSortedMap added in v1.5.0

func NewSortedMap(cmp Comparator, kvs []Value) *SortedMap

func (*SortedMap) Arity added in v1.5.0

func (m *SortedMap) Arity() int

func (*SortedMap) Assoc added in v1.5.0

func (m *SortedMap) Assoc(key, val Value) Associative

func (*SortedMap) Conj added in v1.5.0

func (m *SortedMap) Conj(value Value) Collection

func (*SortedMap) Contains added in v1.5.0

func (m *SortedMap) Contains(key Value) Boolean

func (*SortedMap) Count added in v1.5.0

func (m *SortedMap) Count() Value

func (*SortedMap) Dissoc added in v1.5.0

func (m *SortedMap) Dissoc(key Value) Associative

func (*SortedMap) Empty added in v1.5.0

func (m *SortedMap) Empty() Collection

func (*SortedMap) Hash added in v1.5.0

func (m *SortedMap) Hash() uint32

func (*SortedMap) Invoke added in v1.5.0

func (m *SortedMap) Invoke(args []Value) (Value, error)

func (*SortedMap) Meta added in v1.5.0

func (m *SortedMap) Meta() Value

func (*SortedMap) RSeq added in v1.5.0

func (m *SortedMap) RSeq() Seq

RSeq returns entries in reverse sorted order.

func (*SortedMap) RawCount added in v1.5.0

func (m *SortedMap) RawCount() int

func (*SortedMap) Seq added in v1.5.0

func (m *SortedMap) Seq() Seq

func (*SortedMap) String added in v1.5.0

func (m *SortedMap) String() string

func (*SortedMap) Type added in v1.5.0

func (m *SortedMap) Type() ValueType

func (*SortedMap) Unbox added in v1.5.0

func (m *SortedMap) Unbox() any

func (*SortedMap) ValueAt added in v1.5.0

func (m *SortedMap) ValueAt(key Value) Value

func (*SortedMap) ValueAtOr added in v1.5.0

func (m *SortedMap) ValueAtOr(key, dflt Value) Value

func (*SortedMap) WithMeta added in v1.5.0

func (m *SortedMap) WithMeta(meta Value) Value

type SortedMapSeq added in v1.5.0

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

SortedMapSeq implements Seq over sorted map entries.

func (*SortedMapSeq) Cons added in v1.5.0

func (s *SortedMapSeq) Cons(val Value) Seq

func (*SortedMapSeq) Count added in v1.5.0

func (s *SortedMapSeq) Count() Value

func (*SortedMapSeq) First added in v1.5.0

func (s *SortedMapSeq) First() Value

func (*SortedMapSeq) More added in v1.5.0

func (s *SortedMapSeq) More() Seq

func (*SortedMapSeq) Next added in v1.5.0

func (s *SortedMapSeq) Next() Seq

func (*SortedMapSeq) RawCount added in v1.5.0

func (s *SortedMapSeq) RawCount() int

func (*SortedMapSeq) String added in v1.5.0

func (s *SortedMapSeq) String() string

func (*SortedMapSeq) Type added in v1.5.0

func (s *SortedMapSeq) Type() ValueType

func (*SortedMapSeq) Unbox added in v1.5.0

func (s *SortedMapSeq) Unbox() any

type SortedSet added in v1.5.0

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

func NewSortedSet added in v1.5.0

func NewSortedSet(cmp Comparator, vals []Value) *SortedSet

func (*SortedSet) Arity added in v1.5.0

func (s *SortedSet) Arity() int

func (*SortedSet) Conj added in v1.5.0

func (s *SortedSet) Conj(value Value) Collection

func (*SortedSet) Cons added in v1.5.0

func (s *SortedSet) Cons(val Value) Seq

func (*SortedSet) Contains added in v1.5.0

func (s *SortedSet) Contains(value Value) Boolean

func (*SortedSet) Count added in v1.5.0

func (s *SortedSet) Count() Value

func (*SortedSet) Disj added in v1.5.0

func (s *SortedSet) Disj(value Value) *SortedSet

func (*SortedSet) Empty added in v1.5.0

func (s *SortedSet) Empty() Collection

func (*SortedSet) First added in v1.5.0

func (s *SortedSet) First() Value

func (*SortedSet) Hash added in v1.5.0

func (s *SortedSet) Hash() uint32

func (*SortedSet) Invoke added in v1.5.0

func (s *SortedSet) Invoke(pargs []Value) (Value, error)

func (*SortedSet) Meta added in v1.5.0

func (s *SortedSet) Meta() Value

func (*SortedSet) More added in v1.5.0

func (s *SortedSet) More() Seq

func (*SortedSet) Next added in v1.5.0

func (s *SortedSet) Next() Seq

func (*SortedSet) RSeq added in v1.5.0

func (s *SortedSet) RSeq() Seq

RSeq returns elements in reverse sorted order.

func (*SortedSet) RawCount added in v1.5.0

func (s *SortedSet) RawCount() int

func (*SortedSet) Seq added in v1.5.0

func (s *SortedSet) Seq() Seq

func (*SortedSet) String added in v1.5.0

func (s *SortedSet) String() string

func (*SortedSet) Type added in v1.5.0

func (s *SortedSet) Type() ValueType

func (*SortedSet) Unbox added in v1.5.0

func (s *SortedSet) Unbox() any

func (*SortedSet) ValueAt added in v1.5.0

func (s *SortedSet) ValueAt(key Value) Value

func (*SortedSet) ValueAtOr added in v1.5.0

func (s *SortedSet) ValueAtOr(key Value, dflt Value) Value

func (*SortedSet) WithMeta added in v1.5.0

func (s *SortedSet) WithMeta(m Value) Value

type SortedSetSeq added in v1.5.0

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

func (*SortedSetSeq) Cons added in v1.5.0

func (s *SortedSetSeq) Cons(val Value) Seq

func (*SortedSetSeq) Count added in v1.5.0

func (s *SortedSetSeq) Count() Value

func (*SortedSetSeq) First added in v1.5.0

func (s *SortedSetSeq) First() Value

func (*SortedSetSeq) More added in v1.5.0

func (s *SortedSetSeq) More() Seq

func (*SortedSetSeq) Next added in v1.5.0

func (s *SortedSetSeq) Next() Seq

func (*SortedSetSeq) RawCount added in v1.5.0

func (s *SortedSetSeq) RawCount() int

func (*SortedSetSeq) String added in v1.5.0

func (s *SortedSetSeq) String() string

func (*SortedSetSeq) Type added in v1.5.0

func (s *SortedSetSeq) Type() ValueType

func (*SortedSetSeq) Unbox added in v1.5.0

func (s *SortedSetSeq) Unbox() any

type SourceInfo

type SourceInfo struct {
	File      string
	Line      int // 0-based
	Column    int // 0-based
	EndLine   int
	EndColumn int
	Symbol    string
}

SourceInfo tracks the source location of a form.

Symbol is an optional user-visible name for the value the form binds (e.g. a let-binding or parameter name). It is empty for SourceInfos attached purely for line/column tracking, and populated by the IR builder when a value flows through a `bind-local!` site so downstream passes (notably lower-go) can emit human-readable identifiers.

func (*SourceInfo) String

func (s *SourceInfo) String() string

type SourceMap

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

SourceMap maps bytecode IP offsets to source locations.

It can be built eagerly (Add/Reserve) or lazily: NewLazySourceMap holds a decode closure that is run at most once, on the first Lookup/Entries. Bundle load decodes every chunk's source map, yet source maps are only read on an error or stack-trace — so deferring the decode removes that allocation from the hot startup path entirely for the common (no-error) case.

func NewLazySourceMap added in v1.12.0

func NewLazySourceMap(decode func() []SourceMapEntry) *SourceMap

NewLazySourceMap returns a SourceMap whose entries are produced by `decode` on first access. `decode` runs at most once (memoized); it must be safe to call from any goroutine that first touches the map.

func NewLazySourceMapRaw added in v1.12.0

func NewLazySourceMapRaw(raw []byte, strings []string, count int) *SourceMap

NewLazySourceMapRaw returns a SourceMap that decodes `count` entries from the raw LGB source-map bytes on first access. Each entry is 6 unsigned LEB128 varints: startIP, file(index into strings), line, col, endLine, endColumn. `raw` may alias the bundle buffer (read-only) and `strings` the module string table — both are retained, not copied.

func NewSourceMap

func NewSourceMap() *SourceMap

NewSourceMap creates a new empty SourceMap.

func NewSourceMapWithCapacity added in v1.11.1

func NewSourceMapWithCapacity(n int) *SourceMap

NewSourceMapWithCapacity creates an empty SourceMap with preallocated storage for n entries.

func (*SourceMap) Add

func (sm *SourceMap) Add(ip int, info SourceInfo)

Add records a source location for the given instruction pointer offset.

func (*SourceMap) Entries added in v1.3.0

func (sm *SourceMap) Entries() []SourceMapEntry

Entries returns the source map entries.

func (*SourceMap) Lookup

func (sm *SourceMap) Lookup(ip int) *SourceInfo

Lookup finds the SourceInfo for a given instruction pointer. Uses the last entry whose startIP <= ip.

func (*SourceMap) Reserve added in v1.11.1

func (sm *SourceMap) Reserve(n int)

Reserve grows the backing array so that n subsequent Add calls do not reallocate. The decoder knows the entry count up front (it reads a counted section), so a single sized allocation replaces O(n) append-growth garbage — the dominant source of startup heap churn.

type SourceMapEntry added in v1.3.0

type SourceMapEntry struct {
	StartIP int
	Info    SourceInfo
}

SourceMapEntry is the exported version of sourceMapEntry.

type String

type String string

String is boxed int

func (String) Conj

func (l String) Conj(value Value) Collection

func (String) Cons

func (l String) Cons(val Value) Seq

Cons implements Seq

func (String) Count

func (l String) Count() Value

func (String) Empty

func (l String) Empty() Collection

func (String) First

func (l String) First() Value

First implements Seq

func (String) Hash

func (l String) Hash() uint32

Hash implements Hashable for fast map lookups.

func (String) InvokeMethod added in v1.8.0

func (l String) InvokeMethod(name Symbol, args []Value) (Value, error)

func (String) More

func (l String) More() Seq

More implements Seq

func (String) Next

func (l String) Next() Seq

Next implements Seq

func (String) Nth added in v1.11.0

func (l String) Nth(i int) Value

Nth implements Indexed: positional access by integer index.

func (String) RawCount

func (l String) RawCount() int

func (String) Seq

func (l String) Seq() Seq

func (String) String

func (l String) String() string

String returns the EDN/Clojure-readable form: surrounded by double quotes with EDN-conformant escapes. NOTE: Go's %q emits \xNN / \a / \v for control chars, which the reader rejects ("unknown escape sequence \x") and which are not valid EDN — so %q did not round-trip its own output (e.g. ANSI-colored strings like "\x1b[32m..."). Escapes here match the reader's accepted set (reader.go): \" \\ \t \r \n \b \f, and \uXXXX for everything else below 0x20 plus DEL; printable Unicode passes through as raw UTF-8.

func (String) Type

func (l String) Type() ValueType

Type implements Value

func (String) Unbox

func (l String) Unbox() any

Unbox implements Unbox

func (String) ValueAt

func (l String) ValueAt(key Value) Value

func (String) ValueAtOr

func (l String) ValueAtOr(key Value, dflt Value) Value

type StructMapping

type StructMapping struct {
	RecType *RecordType
	GoType  reflect.Type
	// contains filtered or unexported fields
}

StructMapping holds the bidirectional mapping between a Go struct type and a RecordType.

func LookupStructMapping

func LookupStructMapping(goType reflect.Type) *StructMapping

LookupStructMapping returns the mapping for a Go type, or nil if not registered.

func LookupStructMappingByRecord

func LookupStructMappingByRecord(rt *RecordType) *StructMapping

LookupStructMappingByRecord returns the mapping for a RecordType, or nil.

func RegisterStruct

func RegisterStruct[T any](name string) *StructMapping

RegisterStruct registers a Go struct type T and returns its StructMapping. Usage: mapping := vm.RegisterStruct[MyStruct]("my-ns/MyStruct")

func RegisterStructType

func RegisterStructType(goType reflect.Type, name string) *StructMapping

RegisterStructType registers a Go struct type and creates a corresponding RecordType. The name parameter sets the record type name. Field names are derived from exported struct fields: use `letgo:"name"` struct tag for custom names, otherwise fields are converted from CamelCase to kebab-case (e.g. FirstName → first-name). Fields tagged `letgo:"-"` are skipped.

func (*StructMapping) RecordToStruct

func (m *StructMapping) RecordToStruct(r *Record, target any) error

RecordToStruct populates a Go struct from a Record's fields. If the Record has an origin of the same type, returns it directly (fast path).

func (*StructMapping) StructToRecord

func (m *StructMapping) StructToRecord(v any) *Record

StructToRecord converts a Go struct value to a Record. The original value is stored for fast roundtrip back to Go. Uses cached per-field converters to avoid BoxValue dispatch overhead.

type Symbol

type Symbol string

Symbol is a string

func FuzzySymbolLookup

func FuzzySymbolLookup(ns *Namespace, s Symbol, lookupPrivate bool) []Symbol

func (Symbol) Hash

func (l Symbol) Hash() uint32

Hash implements Hashable for fast map lookups.

func (Symbol) Name

func (l Symbol) Name() Value

func (Symbol) Namespace

func (l Symbol) Namespace() Value

func (Symbol) Namespaced

func (l Symbol) Namespaced() (Value, Value)

func (Symbol) NamespacedRaw added in v1.12.0

func (l Symbol) NamespacedRaw() (ns Symbol, name Symbol, hasNS bool)

NamespacedRaw splits "ns/name" WITHOUT allocating: IndexByte finds the separator and the two parts are substrings (which share the receiver's string backing — no new allocation), returned as raw Symbols rather than boxed into Value interfaces. hasNS is false for an unqualified symbol and for the bare "/" symbol. This is the hot path — it does NOT touch the lookup-stats mutex; the boxing Namespaced() below carries that.

func (Symbol) String

func (l Symbol) String() string

func (Symbol) Type

func (l Symbol) Type() ValueType

Type implements Value

func (Symbol) Unbox

func (l Symbol) Unbox() any

Unbox implements Unbox

type ThrownError

type ThrownError struct {
	Value Value // the thrown value (ExInfo or any Value)
}

ThrownError wraps a Value that was explicitly thrown. It propagates through the normal error return path.

func NewThrownError

func NewThrownError(v Value) *ThrownError

func (*ThrownError) Error

func (e *ThrownError) Error() string

type TransientMap

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

TransientMap is a mutable version of PersistentMap for batch operations. Mutations modify nodes in place instead of path-copying. Call persistent! to freeze back to an immutable PersistentMap.

func NewTransientMap

func NewTransientMap(m *PersistentMap) *TransientMap

func (*TransientMap) Arity added in v1.6.0

func (t *TransientMap) Arity() int

func (*TransientMap) Assoc

func (t *TransientMap) Assoc(key Value, val Value) (*TransientMap, error)

Assoc mutates the transient map in place.

func (*TransientMap) Conj

func (t *TransientMap) Conj(value Value) (*TransientMap, error)

Conj adds a [key val] pair.

func (*TransientMap) Contains added in v1.6.0

func (t *TransientMap) Contains(key Value) Boolean

func (*TransientMap) Count

func (t *TransientMap) Count() Value

func (*TransientMap) Dissoc

func (t *TransientMap) Dissoc(key Value) (*TransientMap, error)

Dissoc mutates the transient map in place.

func (*TransientMap) Invoke added in v1.6.0

func (t *TransientMap) Invoke(args []Value) (Value, error)

func (*TransientMap) Persistent

func (t *TransientMap) Persistent() (*PersistentMap, error)

Persistent freezes the transient and returns an immutable PersistentMap.

func (*TransientMap) RawCount

func (t *TransientMap) RawCount() int

func (*TransientMap) Seq added in v1.11.1

func (t *TransientMap) Seq() Seq

func (*TransientMap) String

func (t *TransientMap) String() string

func (*TransientMap) Type

func (t *TransientMap) Type() ValueType

func (*TransientMap) Unbox

func (t *TransientMap) Unbox() any

func (*TransientMap) ValueAt

func (t *TransientMap) ValueAt(key Value) Value

ValueAt for lookups during construction.

func (*TransientMap) ValueAtOr

func (t *TransientMap) ValueAtOr(key Value, notFound Value) Value

type TransientSet added in v1.6.0

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

TransientSet is a mutable version of PersistentSet for batch ops.

func NewTransientSet added in v1.6.0

func NewTransientSet(s *PersistentSet) *TransientSet

func (*TransientSet) Arity added in v1.6.0

func (t *TransientSet) Arity() int

func (*TransientSet) Conj added in v1.6.0

func (t *TransientSet) Conj(value Value) (*TransientSet, error)

func (*TransientSet) Contains added in v1.6.0

func (t *TransientSet) Contains(key Value) Boolean

func (*TransientSet) Count added in v1.6.0

func (t *TransientSet) Count() Value

func (*TransientSet) Disj added in v1.6.0

func (t *TransientSet) Disj(value Value) (*TransientSet, error)

func (*TransientSet) Invoke added in v1.6.0

func (t *TransientSet) Invoke(args []Value) (Value, error)

func (*TransientSet) Persistent added in v1.6.0

func (t *TransientSet) Persistent() (*PersistentSet, error)

func (*TransientSet) RawCount added in v1.6.0

func (t *TransientSet) RawCount() int

func (*TransientSet) String added in v1.6.0

func (t *TransientSet) String() string

func (*TransientSet) Type added in v1.6.0

func (t *TransientSet) Type() ValueType

func (*TransientSet) Unbox added in v1.6.0

func (t *TransientSet) Unbox() any

func (*TransientSet) ValueAt added in v1.6.0

func (t *TransientSet) ValueAt(key Value) Value

func (*TransientSet) ValueAtOr added in v1.6.0

func (t *TransientSet) ValueAtOr(key Value, notFound Value) Value

type TransientVector

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

TransientVector is a mutable version of ArrayVector/PersistentVector.

func NewTransientVector

func NewTransientVector(v []Value) *TransientVector

func (*TransientVector) Arity added in v1.6.0

func (t *TransientVector) Arity() int

func (*TransientVector) Assoc

func (t *TransientVector) Assoc(key Value, val Value) (*TransientVector, error)

Assoc sets index to value.

func (*TransientVector) Conj

func (t *TransientVector) Conj(value Value) (*TransientVector, error)

Conj appends to the transient vector in place.

func (*TransientVector) Contains added in v1.6.0

func (t *TransientVector) Contains(key Value) Boolean

func (*TransientVector) Count

func (t *TransientVector) Count() Value

func (*TransientVector) Invoke added in v1.6.0

func (t *TransientVector) Invoke(args []Value) (Value, error)

func (*TransientVector) Nth added in v1.11.0

func (t *TransientVector) Nth(i int) Value

Nth implements Indexed: positional access by integer index. TransientVector is positional but not seqable, so `nth` must reach it through this rather than seq traversal.

func (*TransientVector) Persistent

func (t *TransientVector) Persistent() (Value, error)

Persistent freezes the transient and returns an immutable vector.

func (*TransientVector) Pop added in v1.5.0

func (t *TransientVector) Pop() (*TransientVector, error)

Pop removes the last element from the transient vector.

func (*TransientVector) RawCount

func (t *TransientVector) RawCount() int

func (*TransientVector) String

func (t *TransientVector) String() string

func (*TransientVector) Type

func (t *TransientVector) Type() ValueType

func (*TransientVector) Unbox

func (t *TransientVector) Unbox() any

func (*TransientVector) ValueAt

func (t *TransientVector) ValueAt(key Value) Value

func (*TransientVector) ValueAtOr added in v1.6.0

func (t *TransientVector) ValueAtOr(key Value, notFound Value) Value

type TypeError

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

TypeError is a LETGO type error which mostly happens when there is a type mismatch between either LETGO values or LETGO values and Go values. These errors print as:

TypeError: (encountered type name) ... message ... (expected type name)

func NewTypeError

func NewTypeError(value any, message string, expected ValueType) *TypeError

NewTypeError creates a new type error. This error will print the problematic value's (either interface{} or Value) type name, a message, and expected type name.

func (*TypeError) Error

func (te *TypeError) Error() string

Error implements error

func (*TypeError) GetCause

func (te *TypeError) GetCause() error

func (*TypeError) Wrap

func (te *TypeError) Wrap(e error) errors.Error

type TypeUnion added in v1.12.0

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

TypeUnion is a reusable class/interface descriptor backed by several concrete let-go value types. It is a Value but deliberately not a ValueType: no runtime value has the union itself as its concrete type.

func NewTypeUnion added in v1.12.0

func NewTypeUnion(name string, types ...ValueType) *TypeUnion

func (*TypeUnion) Contains added in v1.12.0

func (u *TypeUnion) Contains(valueType ValueType) bool

func (*TypeUnion) String added in v1.12.0

func (u *TypeUnion) String() string

func (*TypeUnion) Type added in v1.12.0

func (u *TypeUnion) Type() ValueType

func (*TypeUnion) Types added in v1.12.0

func (u *TypeUnion) Types() []ValueType

func (*TypeUnion) Unbox added in v1.12.0

func (u *TypeUnion) Unbox() any

type TypedArray added in v1.3.1

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

TypedArray is a mutable, typed array backed by a native Go slice. Unlike persistent collections, arrays support in-place mutation via Set.

func NewByteArray added in v1.3.1

func NewByteArray(size int) *TypedArray

func NewByteArrayFrom added in v1.3.1

func NewByteArrayFrom(data []byte) *TypedArray

func NewFloatArray added in v1.3.1

func NewFloatArray(size int) *TypedArray

func NewFloatArrayFrom added in v1.3.1

func NewFloatArrayFrom(data []float64) *TypedArray

func NewIntArray added in v1.3.1

func NewIntArray(size int) *TypedArray

func NewIntArrayFrom added in v1.3.1

func NewIntArrayFrom(data []int64) *TypedArray

func NewObjectArray added in v1.3.1

func NewObjectArray(size int) *TypedArray

func NewObjectArrayFrom added in v1.3.1

func NewObjectArrayFrom(data []Value) *TypedArray

func (*TypedArray) Arity added in v1.3.1

func (a *TypedArray) Arity() int

func (*TypedArray) Clone added in v1.3.1

func (a *TypedArray) Clone() *TypedArray

Clone returns a shallow copy.

func (*TypedArray) Conj added in v1.3.1

func (a *TypedArray) Conj(v Value) Collection

func (*TypedArray) Count added in v1.3.1

func (a *TypedArray) Count() Value

func (*TypedArray) Empty added in v1.3.1

func (a *TypedArray) Empty() Collection

func (*TypedArray) Get added in v1.3.1

func (a *TypedArray) Get(i int) Value

Get returns the element at index i as a boxed Value.

func (*TypedArray) Invoke added in v1.3.1

func (a *TypedArray) Invoke(args []Value) (Value, error)

func (*TypedArray) Kind added in v1.3.1

func (a *TypedArray) Kind() ArrayKind

Kind returns the element kind.

func (*TypedArray) Len added in v1.3.1

func (a *TypedArray) Len() int

func (*TypedArray) Meta added in v1.3.1

func (a *TypedArray) Meta() Value

Meta implements IMeta — arrays don't carry metadata.

func (*TypedArray) Nth added in v1.11.0

func (a *TypedArray) Nth(i int) Value

Nth implements Indexed: positional access by integer index.

func (*TypedArray) RawCount added in v1.3.1

func (a *TypedArray) RawCount() int

func (*TypedArray) Seq added in v1.3.1

func (a *TypedArray) Seq() Seq

func (*TypedArray) Set added in v1.3.1

func (a *TypedArray) Set(i int, v Value) error

Set sets the element at index i, coercing v to the element type.

func (*TypedArray) String added in v1.3.1

func (a *TypedArray) String() string

func (*TypedArray) Type added in v1.3.1

func (a *TypedArray) Type() ValueType

func (*TypedArray) Unbox added in v1.3.1

func (a *TypedArray) Unbox() any

Unbox returns the underlying Go slice directly for interop.

func (*TypedArray) ValueAt added in v1.3.1

func (a *TypedArray) ValueAt(key Value) Value

func (*TypedArray) ValueAtOr added in v1.3.1

func (a *TypedArray) ValueAtOr(key Value, dflt Value) Value

func (*TypedArray) WithMeta added in v1.3.1

func (a *TypedArray) WithMeta(_ Value) Value

WithMeta implements IMeta — returns self (arrays don't support metadata).

type TypedArraySeq added in v1.3.1

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

func (*TypedArraySeq) Conj added in v1.3.1

func (s *TypedArraySeq) Conj(val Value) Collection

func (*TypedArraySeq) Cons added in v1.3.1

func (s *TypedArraySeq) Cons(val Value) Seq

func (*TypedArraySeq) Count added in v1.3.1

func (s *TypedArraySeq) Count() Value

func (*TypedArraySeq) Empty added in v1.3.1

func (s *TypedArraySeq) Empty() Collection

func (*TypedArraySeq) First added in v1.3.1

func (s *TypedArraySeq) First() Value

func (*TypedArraySeq) Meta added in v1.3.1

func (s *TypedArraySeq) Meta() Value

func (*TypedArraySeq) More added in v1.3.1

func (s *TypedArraySeq) More() Seq

func (*TypedArraySeq) Next added in v1.3.1

func (s *TypedArraySeq) Next() Seq

func (*TypedArraySeq) Nth added in v1.11.0

func (s *TypedArraySeq) Nth(i int) Value

Nth implements Indexed: positional access by integer index.

func (*TypedArraySeq) RawCount added in v1.3.1

func (s *TypedArraySeq) RawCount() int

func (*TypedArraySeq) Seq added in v1.3.1

func (s *TypedArraySeq) Seq() Seq

func (*TypedArraySeq) String added in v1.3.1

func (s *TypedArraySeq) String() string

func (*TypedArraySeq) Type added in v1.3.1

func (s *TypedArraySeq) Type() ValueType

func (*TypedArraySeq) Unbox added in v1.3.1

func (s *TypedArraySeq) Unbox() any

func (*TypedArraySeq) ValueAt added in v1.3.1

func (s *TypedArraySeq) ValueAt(key Value) Value

func (*TypedArraySeq) ValueAtOr added in v1.3.1

func (s *TypedArraySeq) ValueAtOr(key Value, dflt Value) Value

func (*TypedArraySeq) WithMeta added in v1.3.1

func (s *TypedArraySeq) WithMeta(_ Value) Value

type UUID added in v1.5.0

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

UUID holds a UUID string in canonical lowercase form.

func NewUUID added in v1.5.0

func NewUUID(s string) *UUID

NewUUID creates a UUID from an already-validated canonical string.

func ParseUUID added in v1.5.0

func ParseUUID(s string) *UUID

ParseUUID parses a UUID string. Returns nil if invalid.

func (*UUID) Equals added in v1.7.0

func (u *UUID) Equals(other Value) bool

func (*UUID) Hash added in v1.5.0

func (u *UUID) Hash() uint32

Hash implements Hashable.

func (*UUID) String added in v1.5.0

func (u *UUID) String() string

func (*UUID) Type added in v1.5.0

func (u *UUID) Type() ValueType

func (*UUID) Unbox added in v1.5.0

func (u *UUID) Unbox() any

type Value

type Value interface {
	fmt.Stringer
	Type() ValueType
	Unbox() any
}

Value is implemented by all LETGO values

func BoxValue

func BoxValue(v reflect.Value) (Value, error)

func ErrorToValue added in v1.11.0

func ErrorToValue(err error) Value

ErrorToValue is the exported entry point used by gogen_ir-lowered Go code to convert a Go error returned by an invoked try body/handler into the catchable Value that a (catch e ...) handler binds. Mirrors the bytecode VM's handler path (vm.go handleError), so AOT-lowered try/catch sees the same caught value.

func MakeFloat

func MakeFloat(v float64) Value

MakeFloat returns a Float Value.

func MakeInt

func MakeInt(v int) Value

MakeInt returns a cached Value for small ints, avoiding heap allocation.

func MaybeDowngrade

func MaybeDowngrade(b *big.Int) Value

MaybeDowngrade returns an Int if the BigInt fits in int64, otherwise BigInt.

func MaybeSimplifyRatio added in v1.5.0

func MaybeSimplifyRatio(r *big.Rat) Value

MaybeSimplifyRatio returns an Int/BigInt if denominator is 1, otherwise Ratio.

func MustBox added in v1.9.0

func MustBox(v any) Value

MustBox boxes a Go value via BoxValue and panics on error. Intended for use at init time (e.g. namespace install functions) where boxing failure is a programmer error, not a runtime condition.

func NewArrayVector

func NewArrayVector(v []Value) Value

func NewList

func NewList(vs []Value) Value

func NewMap

func NewMap(v []Value) Value

func NewPersistentVector

func NewPersistentVector(values []Value) Value

func NewRange

func NewRange(start, end, step Int) Value

func NewRegex

func NewRegex(s string) (Value, error)

func NewSet

func NewSet(v []Value) Value

func NumAbs

func NumAbs(a Value) (Value, error)

NumAbs returns absolute value.

func NumAdd

func NumAdd(a, b Value) (Value, error)

NumAdd adds two numeric Values.

func NumAddP added in v1.8.0

func NumAddP(a, b Value) (Value, error)

NumAddP is `+` with overflow promotion for Int+Int. All other type combinations match NumAdd exactly. Delegating to NumAdd for the non-Int/Int paths is safe because NumAdd's BigInt branches return NewBigInt(...) directly (no MaybeDowngrade), preserving BigInt identity through `+'`. The same invariant is relied on by NumSubP and NumMulP below — if you change MaybeDowngrade usage in NumAdd/Sub/Mul, re-check the eval tests `(bigint? (+' 1 1N))` etc. NumNeg DOES downgrade *BigInt, hence the explicit branch in NumNegP. Naming mirrors Clojure JVM's `addP`/`multiplyP` precedent.

func NumDiv

func NumDiv(a, b Value) (Value, error)

NumDiv divides a by b. Int/Int returns Float when not exact.

func NumMod

func NumMod(a, b Value) (Value, error)

NumMod computes the floored modulus (like Clojure's mod). Sign follows the divisor: (mod -10 3) => 2

func NumMul

func NumMul(a, b Value) (Value, error)

NumMul multiplies two numeric Values.

func NumMulP added in v1.8.0

func NumMulP(a, b Value) (Value, error)

NumMulP is `*` with overflow promotion for Int*Int.

func NumNeg

func NumNeg(a Value) (Value, error)

NumNeg negates a numeric value.

func NumNegP added in v1.8.0

func NumNegP(a Value) (Value, error)

NumNegP is unary `-` with overflow promotion at math.MinInt. For *BigInt we negate directly without downgrading — `(-' 1N)` must return `-1N`, not `Int -1` (Clojure preserves BigInt identity through promoting ops). NumNeg in pkg/vm/numbers.go does downgrade, hence the explicit BigInt branch here.

func NumQuot

func NumQuot(a, b Value) (Value, error)

NumQuot performs integer division (quot in Clojure).

func NumRem added in v1.3.1

func NumRem(a, b Value) (Value, error)

NumRem computes the remainder of truncated division (like Java's %). Sign follows the dividend: (rem -10 3) => -1

func NumSub

func NumSub(a, b Value) (Value, error)

NumSub subtracts b from a.

func NumSubP added in v1.8.0

func NumSubP(a, b Value) (Value, error)

NumSubP is `-` with overflow promotion for Int-Int.

func RunWithBindings added in v1.8.0

func RunWithBindings(snap BindingSnapshot, fn func() (Value, error)) (Value, error)

RunWithBindings runs fn with snap installed as the root context's dynamic bindings, restoring the prior state afterwards. This is the legacy process-global bracketing used by spawn sites that have not yet moved to a child ExecContext; true per-goroutine isolation comes from running fn under ec.Child() instead (see docs/design/exec-context-threading.md).

func SeqToSlice added in v1.8.0

func SeqToSlice(v Value) ([]Value, error)

SeqToSlice realizes a let-go sequence value into a []Value. Useful when a Go caller has a vm.Value and explicitly wants a slice. Returns nil for nil/NIL/empty input. Returns an error if v isn't a sequence.

For infinite sequences this will not terminate — use Iter and break instead.

func ToLetGo

func ToLetGo(v any) (Value, error)

type ValueType

type ValueType interface {
	Value
	Name() string
	Box(any) (Value, error)
}

ValueType represents a type of a Value

type Var

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

func NewVar

func NewVar(nsref *Namespace, ns string, name string) *Var

func (*Var) AddWatch added in v1.8.0

func (v *Var) AddWatch(key Value, fn Fn)

func (*Var) AlterMeta added in v1.9.0

func (v *Var) AlterMeta(fn Fn, args []Value) (Value, error)

func (*Var) AlterRoot added in v1.8.0

func (v *Var) AlterRoot(fn Fn) (Value, error)

func (*Var) AlterRootArgs added in v1.8.0

func (v *Var) AlterRootArgs(fn Fn, args []Value) (Value, error)

func (*Var) Arity

func (v *Var) Arity() int

func (*Var) Deref

func (v *Var) Deref() Value

Deref returns the current value in the root execution context: the dynamic top binding if one is active, else the root. Host and lowered callers that hold no ExecContext resolve here; the interpreter resolves against its frame's context via ExecContext.deref (which shares derefRoot for the root).

func (*Var) GuardRoot added in v1.12.0

func (v *Var) GuardRoot()

GuardRoot marks the var's CURRENT root as the canonical value of a native primitive. Any later root mutation to a different value (with-redefs, alter-var-root, re-def) bumps the global deviation counter, steering lowered direct-call sites onto the trampoline until the root is restored.

func (*Var) Invoke

func (v *Var) Invoke(values []Value) (Value, error)

func (*Var) IsBound added in v1.10.0

func (v *Var) IsBound() bool

IsBound reports whether the var has any bound value — a root binding OR an active dynamic binding — matching Clojure's bound?. A var interned by the compiler for a forward `(def x v)` (before it runs) has neither yet, which distinguishes "declared but unset" from "set", as `defonce` needs.

func (*Var) IsDynamic

func (v *Var) IsDynamic() bool

func (*Var) IsMacro

func (v *Var) IsMacro() bool

func (*Var) IsPrivate

func (v *Var) IsPrivate() bool

func (*Var) Meta added in v1.9.0

func (v *Var) Meta() Value

func (*Var) NS added in v1.3.0

func (v *Var) NS() string

NS returns the namespace name.

func (*Var) PopBinding

func (v *Var) PopBinding()

PopBinding removes the most recent dynamic binding in the root context.

func (*Var) PushBinding

func (v *Var) PushBinding(val Value)

PushBinding pushes a dynamic binding value in the root execution context.

func (*Var) RemoveWatch added in v1.8.0

func (v *Var) RemoveWatch(key Value)

func (*Var) Root added in v1.8.0

func (v *Var) Root() Value

Root returns the var's root binding directly, bypassing any current dynamic binding on the stack. Use this where Clojure semantics require the root (e.g. alter-var-root) rather than the currently visible deref value.

func (*Var) SetDynamic

func (v *Var) SetDynamic()

func (*Var) SetMacro

func (v *Var) SetMacro()

func (*Var) SetMeta added in v1.9.0

func (v *Var) SetMeta(meta Value)

func (*Var) SetPrivate

func (v *Var) SetPrivate()

func (*Var) SetRoot

func (v *Var) SetRoot(val Value) *Var

func (*Var) String

func (v *Var) String() string

func (*Var) Type

func (v *Var) Type() ValueType

func (*Var) Unbox

func (v *Var) Unbox() any

func (*Var) VarName added in v1.3.0

func (v *Var) VarName() string

VarName returns the var name.

type Void

type Void struct{}

Void is a Value whose only value is Void

var VOID *Void = VoidType.zero

NIL is the only value of VoidType (and only instance of VoidValue)

func (*Void) String

func (n *Void) String() string

func (*Void) Type

func (n *Void) Type() ValueType

Type implements Value

func (*Void) Unbox

func (n *Void) Unbox() any

Unbox implements Value

type Volatile

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

Volatile is a mutable container with no synchronization. Useful for transducers and other single-threaded mutation contexts.

func NewVolatile

func NewVolatile(v Value) *Volatile

func (*Volatile) Deref

func (v *Volatile) Deref() Value

func (*Volatile) Reset

func (v *Volatile) Reset(val Value) Value

func (*Volatile) String

func (v *Volatile) String() string

func (*Volatile) Type

func (v *Volatile) Type() ValueType

func (*Volatile) Unbox

func (v *Volatile) Unbox() any

Jump to

Keyboard shortcuts

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