vm

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

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_TRACE_ENABLE  // enable tracing
	OP_TRACE_DISABLE // disable tracing

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

Opcodes

Variables

View Source
var ArrayVectorType *theArrayVectorType = &theArrayVectorType{}

ArrayVectorType is the type of ArrayVectors

View Source
var AtomType *theAtomType = &theAtomType{}
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

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 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 ExInfoType *theExInfoType = &theExInfoType{}
View Source
var FloatType *theFloatType = &theFloatType{zero: 0}

FloatType is the type of Float values

View Source
var FormSource = &formSourceMap{m: map[interface{}]*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 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 PromiseType *thePromiseType = &thePromiseType{}
View Source
var ProtocolType *theProtocolType = &theProtocolType{}
View Source
var RangeType *theRangeType = &theRangeType{}

RangeType is the type of Lists

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 SequenceType *theSequenceType = &theSequenceType{}

SequenceType is the type of Sequences

View Source
var SetType *theSetType = &theSetType{}

ArrayVectorType is the type of ArrayVectors

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 TransientMapType *theTransientMapType = &theTransientMapType{}
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 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 FormatError

func FormatError(err error) string

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

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 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 IsReduced

func IsReduced(v Value) bool

func IsTruthy

func IsTruthy(v Value) bool

func NumEq

func NumEq(a, b Value) bool

NumEq tests numeric equality (cross-type: 1 == 1.0 is true).

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 OpcodeToString

func OpcodeToString(op int32) string

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 SetNSLookup

func SetNSLookup(fn func(string) *Namespace)

SetNSLookup sets the global namespace lookup function.

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 an Int, Float, or BigInt to float64.

func ToInt

func ToInt(v Value) (int, bool)

ToInt converts a numeric Value to int 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 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) RawCount

func (l ArrayVector) RawCount() int

func (ArrayVector) Seq

func (l ArrayVector) Seq() Seq

func (ArrayVector) String

func (l ArrayVector) String() string

func (ArrayVector) Type

func (l ArrayVector) Type() ValueType

func (ArrayVector) Unbox

func (l ArrayVector) Unbox() interface{}

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

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) 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() interface{}

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 (*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) Deref

func (a *Atom) Deref() Value

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

func (*Atom) String

func (v *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 (v *Atom) Type() ValueType

func (*Atom) Unbox

func (v *Atom) Unbox() interface{}

func (*Atom) WithMeta

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

type BigInt

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

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

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() interface{}

func (*BigInt) Val

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

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() interface{}

Unbox implements Value

type Boxed

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

func NewBoxed

func NewBoxed(value interface{}) *Boxed

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() interface{}

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() interface{}

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() interface{}

Unbox implements Unbox

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

func (l *Closure) String() string

func (*Closure) Type

func (l *Closure) Type() ValueType

func (*Closure) Unbox

func (l *Closure) Unbox() interface{}

Unbox implements Unbox

type CodeChunk

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

CodeChunk holds bytecode and provides facilities for reading and writing it

func NewCodeChunk

func NewCodeChunk(consts *Consts) *CodeChunk

func (*CodeChunk) AddSourceInfo

func (c *CodeChunk) AddSourceInfo(info SourceInfo)

AddSourceInfo records the source location for the current 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) 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) SetMaxStack

func (c *CodeChunk) SetMaxStack(max int)

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 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) 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() interface{}

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) 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 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() interface{}

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 (*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) Message

func (e *ExInfo) Message() string

func (*ExInfo) String

func (e *ExInfo) String() string

func (*ExInfo) Type

func (e *ExInfo) Type() ValueType

func (*ExInfo) Unbox

func (e *ExInfo) Unbox() interface{}

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() interface{}

Unbox implements Unbox

type Fn

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

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) 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() interface{}

Unbox implements Unbox

type FuncInterface

type FuncInterface func(interface{})

type Hashable

type Hashable interface {
	Hash() uint32
}

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

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 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) 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() interface{}

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() interface{}

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() interface{}

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

func (l Keyword) String() string

func (Keyword) Type

func (l Keyword) Type() ValueType

Type implements Value

func (Keyword) Unbox

func (l Keyword) Unbox() interface{}

Unbox implements Unbox

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) 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() interface{}

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() interface{}

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 Lookup

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

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() interface{}

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.

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() interface{}

type MultiArityFn

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

func (*MultiArityFn) Arity

func (l *MultiArityFn) Arity() int

func (*MultiArityFn) Invoke

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

func (*MultiArityFn) String

func (l *MultiArityFn) String() string

func (*MultiArityFn) Type

func (l *MultiArityFn) Type() ValueType

func (*MultiArityFn) Unbox

func (l *MultiArityFn) Unbox() interface{}

Unbox implements Unbox

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

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

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

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() interface{}

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.

func (*Namespace) Def

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

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) 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) 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() interface{}

Unbox implements Unbox

type NativeFn

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

func (*NativeFn) Arity

func (l *NativeFn) Arity() int

func (*NativeFn) Invoke

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

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() interface{}

Unbox implements Unbox

func (*NativeFn) WithArity

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

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 (l *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 (l *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() interface{}

Unbox implements Value

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 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() interface{}

func (*PersistentMap) ValueAt

func (m *PersistentMap) ValueAt(key 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 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() interface{}

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

func (v PersistentVector) RawCount() int

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() interface{}

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) 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) 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() interface{}

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 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) 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() interface{}

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. implMap is a PersistentMap of {method-keyword → fn}.

func (*Protocol) ExtendNil

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

ExtendNil adds implementations for nil.

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

func (*Protocol) String

func (p *Protocol) String() string

func (*Protocol) Type

func (p *Protocol) Type() ValueType

func (*Protocol) Unbox

func (p *Protocol) Unbox() interface{}

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

func (f *ProtocolFn) String() string

func (*ProtocolFn) Type

func (f *ProtocolFn) Type() ValueType

func (*ProtocolFn) Unbox

func (f *ProtocolFn) Unbox() interface{}

type Range

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

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

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) 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() interface{}

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 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() interface{}

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() interface{}

func (*Record) ValueAt

func (r *Record) ValueAt(key 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 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 interface{}) (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 (rt *RecordType) TypeName() string

TypeName returns the record type name.

func (*RecordType) Unbox

func (t *RecordType) Unbox() interface{}

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() interface{}

type Refer

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

type Reference

type Reference interface {
	Deref() Value
}

type Regex

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

Regex is boxed int

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

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

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

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() interface{}

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() interface{}

Unbox implements Value

type Seq

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

Seq is implemented by all sequence-like values

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() interface{}

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() interface{}

type SetWithMeta

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

SetWithMeta wraps a Set to carry metadata.

func (*SetWithMeta) Meta

func (s *SetWithMeta) Meta() Value

func (*SetWithMeta) WithMeta

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

type SourceInfo

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

SourceInfo tracks the source location of a form.

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.

func NewSourceMap

func NewSourceMap() *SourceMap

NewSourceMap creates a new empty SourceMap.

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.

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

func (l String) More() Seq

More implements Seq

func (String) Next

func (l String) Next() Seq

Next implements Seq

func (String) RawCount

func (l String) RawCount() int

func (String) Seq

func (l String) Seq() Seq

func (String) String

func (l String) String() string

func (String) Type

func (l String) Type() ValueType

Type implements Value

func (String) Unbox

func (l String) Unbox() interface{}

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 interface{}) 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 interface{}) *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) String

func (l Symbol) String() string

func (Symbol) Type

func (l Symbol) Type() ValueType

Type implements Value

func (Symbol) Unbox

func (l Symbol) Unbox() interface{}

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

func (t *TransientMap) Persistent() *PersistentMap

Persistent freezes the transient and returns an immutable PersistentMap.

func (*TransientMap) RawCount

func (t *TransientMap) RawCount() int

func (*TransientMap) String

func (t *TransientMap) String() string

func (*TransientMap) Type

func (t *TransientMap) Type() ValueType

func (*TransientMap) Unbox

func (t *TransientMap) Unbox() interface{}

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

func (t *TransientVector) Count() Value

func (*TransientVector) Persistent

func (t *TransientVector) Persistent() Value

Persistent freezes the transient and returns an immutable 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() interface{}

func (*TransientVector) ValueAt

func (t *TransientVector) ValueAt(key 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 interface{}, 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 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) 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() interface{}

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) 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() interface{}

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 Value

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

Value is implemented by all LETGO values

func BoxValue

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

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 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 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 NumNeg

func NumNeg(a Value) (Value, error)

NumNeg negates a numeric value.

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 ToLetGo

func ToLetGo(v interface{}) (Value, error)

type ValueType

type ValueType interface {
	Value
	Name() string
	Box(interface{}) (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) Arity

func (v *Var) Arity() int

func (*Var) Deref

func (v *Var) Deref() Value

func (*Var) Invoke

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

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

func (*Var) PushBinding

func (v *Var) PushBinding(val Value)

PushBinding pushes a dynamic binding value.

func (*Var) SetDynamic

func (v *Var) SetDynamic()

func (*Var) SetMacro

func (v *Var) SetMacro()

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() interface{}

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() interface{}

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() interface{}

Jump to

Keyboard shortcuts

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