Documentation
¶
Overview ¶
Package values implements all Scheme runtime value types.
The package provides the complete R7RS value system:
Numeric Tower (R7RS 6.2.1) ¶
- Integer, BigInteger: exact integers (int64 and arbitrary precision)
- Rational: exact rationals via math/big.Rat
- Float, BigFloat: inexact reals (float64 and arbitrary precision)
- Complex, BigComplex: complex numbers
All numeric types implement the Number interface for uniform arithmetic.
Core Types ¶
- Boolean: #t and #f singletons (TrueValue, FalseValue)
- Character: Unicode rune wrapper
- String: immutable and mutable string values
- Symbol: identifiers compared by string key
- Pair: cons cells as [2]Value arrays
- Vector: fixed-size mutable value arrays
- ByteVector: byte arrays for binary data
- Hashtable: bucket-chaining hash maps with Hashable keys
I/O Ports (R7RS 6.13) ¶
Port types implement Port, InputPort, OutputPort, and related interfaces:
- CharacterInputPort, CharacterOutputPort: textual I/O
- BinaryInputPort, BinaryOutputPort: binary I/O
- StringInputPort, StringOutputPort: in-memory string ports
- ByteVectorInputPort, ByteVectorOutputPort: in-memory byte ports
Concurrency (SRFI-18+) ¶
- Thread, Mutex, ConditionVariable: SRFI-18 threading
- Channel, WaitGroup, RWMutex, Once: Go concurrency wrappers
- AtomicBox, AtomicInt64: atomic operations
Singletons ¶
Use Void for the absence of a value and EOFObject for end-of-file. EmptyList is the empty list sentinel.
Package values provides Scheme runtime value types.
Index ¶
- Constants
- Variables
- func BigIntegerEqualsFloat(bi *BigInteger, f *Float) bool
- func BooleanToBool(b *Boolean) bool
- func DisplayValueToString(v Value) string
- func EqualTo(a, b Value) bool
- func ExactInteger(v Value) (int64, bool)
- func IntegerEqualsFloat(i *Integer, f *Float) bool
- func IsEmptyList(v Value) bool
- func IsList(v Value) bool
- func IsVoid(v Value) bool
- func Must(v Value, err error)
- func NumberToComplex128(n Number) complex128
- func NumberToFloat64(n Number) float64
- func SchemeTypeName(v Value) string
- func ValidateByteValue(v *Integer, name string, desc string) error
- func ValueToBool(b Value) bool
- func WriteSharedValueToString(v Value) string
- func WriteValueToString(v Value) string
- type AbandonedMutexException
- type AtomicBox
- func (p *AtomicBox) CompareAndSwap(ol, nw Value) bool
- func (p *AtomicBox) EqualTo(v Value) bool
- func (p *AtomicBox) ID() uint64
- func (p *AtomicBox) IsVoid() bool
- func (p *AtomicBox) Load() Value
- func (p *AtomicBox) SchemeString() string
- func (p *AtomicBox) Store(v Value)
- func (p *AtomicBox) Swap(v Value) Value
- type AtomicInt64
- func (p *AtomicInt64) Add(delta int64) int64
- func (p *AtomicInt64) CompareAndSwap(ol, nw int64) bool
- func (p *AtomicInt64) EqualTo(v Value) bool
- func (p *AtomicInt64) ID() uint64
- func (p *AtomicInt64) IsVoid() bool
- func (p *AtomicInt64) Load() int64
- func (p *AtomicInt64) SchemeString() string
- func (p *AtomicInt64) Store(v int64)
- func (p *AtomicInt64) Swap(nw int64) int64
- type BigComplex
- func (p *BigComplex) Abs() Number
- func (p *BigComplex) Add(o Number) Number
- func (p *BigComplex) Compare(o Number) int
- func (p *BigComplex) Conjugate() *BigComplex
- func (p *BigComplex) Divide(o Number) (Number, error)
- func (p *BigComplex) EqualTo(o Value) bool
- func (p *BigComplex) HashCode() uint64
- func (p *BigComplex) Imag() Number
- func (p *BigComplex) ImagAsBigFloat() *BigFloat
- func (p *BigComplex) ImagPart() Number
- func (p *BigComplex) IsExact() bool
- func (p *BigComplex) IsFinite() bool
- func (p *BigComplex) IsInteger() bool
- func (p *BigComplex) IsNaN() bool
- func (p *BigComplex) IsRational() bool
- func (p *BigComplex) IsReal() bool
- func (p *BigComplex) IsVoid() bool
- func (p *BigComplex) IsZero() bool
- func (p *BigComplex) Kind() NumericKind
- func (p *BigComplex) LessThan(o Number) bool
- func (p *BigComplex) Magnitude() *BigFloat
- func (p *BigComplex) Multiply(o Number) Number
- func (p *BigComplex) Negate() Number
- func (p *BigComplex) Phase() *BigFloat
- func (p *BigComplex) Real() Number
- func (p *BigComplex) RealAsBigFloat() *BigFloat
- func (p *BigComplex) RealPart() Number
- func (p *BigComplex) SchemeString() string
- func (p *BigComplex) Subtract(o Number) Number
- func (p *BigComplex) ToExact() (Number, error)
- func (p *BigComplex) ToInexact() Number
- type BigFloat
- func (p *BigFloat) Abs() Number
- func (p *BigFloat) Add(o Number) Number
- func (p *BigFloat) BigFloatValue() *big.Float
- func (p *BigFloat) Compare(o Number) int
- func (p *BigFloat) Divide(o Number) (Number, error)
- func (p *BigFloat) EqualTo(o Value) bool
- func (p *BigFloat) Float64() float64
- func (p *BigFloat) HashCode() uint64
- func (p *BigFloat) IsExact() bool
- func (p *BigFloat) IsFinite() bool
- func (p *BigFloat) IsInteger() bool
- func (p *BigFloat) IsNaN() bool
- func (p *BigFloat) IsNegative() bool
- func (p *BigFloat) IsPositive() bool
- func (p *BigFloat) IsRational() bool
- func (p *BigFloat) IsVoid() bool
- func (p *BigFloat) IsZero() bool
- func (p *BigFloat) Kind() NumericKind
- func (p *BigFloat) LessThan(o Number) bool
- func (p *BigFloat) Multiply(o Number) Number
- func (p *BigFloat) Negate() Number
- func (p *BigFloat) SchemeString() string
- func (p *BigFloat) Sign() int
- func (p *BigFloat) Subtract(o Number) Number
- func (p *BigFloat) ToExact() (Number, error)
- func (p *BigFloat) ToInexact() Number
- type BigInteger
- func (p *BigInteger) Abs() Number
- func (p *BigInteger) Add(o Number) Number
- func (p *BigInteger) BigInt() *big.Int
- func (p *BigInteger) Compare(o Number) int
- func (p *BigInteger) Divide(o Number) (Number, error)
- func (p *BigInteger) EqualTo(o Value) bool
- func (p *BigInteger) HashCode() uint64
- func (p *BigInteger) Int64() int64
- func (p *BigInteger) IsExact() bool
- func (p *BigInteger) IsFinite() bool
- func (p *BigInteger) IsInteger() bool
- func (p *BigInteger) IsNaN() bool
- func (p *BigInteger) IsNegative() bool
- func (p *BigInteger) IsPositive() bool
- func (p *BigInteger) IsRational() bool
- func (p *BigInteger) IsVoid() bool
- func (p *BigInteger) IsZero() bool
- func (p *BigInteger) Kind() NumericKind
- func (p *BigInteger) LessThan(o Number) bool
- func (p *BigInteger) Multiply(o Number) Number
- func (p *BigInteger) Negate() Number
- func (p *BigInteger) SchemeString() string
- func (p *BigInteger) Sign() int
- func (p *BigInteger) Subtract(o Number) Number
- func (p *BigInteger) ToExact() (Number, error)
- func (p *BigInteger) ToInexact() Number
- type BinaryInputPort
- func (p *BinaryInputPort) Close() error
- func (p *BinaryInputPort) Datum() io.Reader
- func (p *BinaryInputPort) EqualTo(v Value) bool
- func (p *BinaryInputPort) IsClosed() bool
- func (p *BinaryInputPort) IsVoid() bool
- func (p *BinaryInputPort) Read(bs []byte) (int, error)
- func (p *BinaryInputPort) ReadByte() (byte, error)
- func (p *BinaryInputPort) SchemeString() string
- func (p *BinaryInputPort) UnreadByte() error
- type BinaryOutputPort
- func (p *BinaryOutputPort) Close() error
- func (p *BinaryOutputPort) Datum() io.Writer
- func (p *BinaryOutputPort) EqualTo(v Value) bool
- func (p *BinaryOutputPort) Flush() error
- func (p *BinaryOutputPort) IsClosed() bool
- func (p *BinaryOutputPort) IsVoid() bool
- func (p *BinaryOutputPort) SchemeString() string
- func (p *BinaryOutputPort) Write(bs []byte) (int, error)
- func (p *BinaryOutputPort) WriteByte(b byte) error
- type BinaryReader
- type BinaryWriter
- type Boolean
- type Box
- type Byte
- type ByteVector
- func (p *ByteVector) AsBytes(is ...int) []byte
- func (p *ByteVector) AsList() Tuple
- func (p *ByteVector) Datum() []*Byte
- func (p *ByteVector) EqualTo(v Value) bool
- func (p *ByteVector) Get(i int) Value
- func (p *ByteVector) IsVoid() bool
- func (p *ByteVector) Length() int
- func (p *ByteVector) SchemeString() string
- func (p *ByteVector) Set(i int, value Value) error
- type ByteVectorBufferedOutputPort
- func (p *ByteVectorBufferedOutputPort) Close() error
- func (p *ByteVectorBufferedOutputPort) Datum() *bytes.Buffer
- func (p *ByteVectorBufferedOutputPort) EqualTo(v Value) bool
- func (p *ByteVectorBufferedOutputPort) Flush() error
- func (p *ByteVectorBufferedOutputPort) IsClosed() bool
- func (p *ByteVectorBufferedOutputPort) IsVoid() bool
- func (p *ByteVectorBufferedOutputPort) ReadByteVector() (*ByteVector, error)
- func (p *ByteVectorBufferedOutputPort) SchemeString() string
- func (p *ByteVectorBufferedOutputPort) Write(bs []byte) (int, error)
- func (p *ByteVectorBufferedOutputPort) WriteByte(b byte) error
- type ByteVectorExtractor
- type ByteVectorInputOutputPort
- func (p *ByteVectorInputOutputPort) Close() error
- func (p *ByteVectorInputOutputPort) Datum() *bytes.Buffer
- func (p *ByteVectorInputOutputPort) EqualTo(v Value) bool
- func (p *ByteVectorInputOutputPort) Flush() error
- func (p *ByteVectorInputOutputPort) IsClosed() bool
- func (p *ByteVectorInputOutputPort) IsVoid() bool
- func (p *ByteVectorInputOutputPort) Read(bs []byte) (int, error)
- func (p *ByteVectorInputOutputPort) ReadByte() (byte, error)
- func (p *ByteVectorInputOutputPort) ReadByteVector() (*ByteVector, error)
- func (p *ByteVectorInputOutputPort) SchemeString() string
- func (p *ByteVectorInputOutputPort) UnreadByte() error
- func (p *ByteVectorInputOutputPort) Write(bs []byte) (int, error)
- func (p *ByteVectorInputOutputPort) WriteByte(b byte) error
- type ByteVectorInputPort
- func (p *ByteVectorInputPort) Close() error
- func (p *ByteVectorInputPort) Datum() *bufio.Reader
- func (p *ByteVectorInputPort) EqualTo(v Value) bool
- func (p *ByteVectorInputPort) IsClosed() bool
- func (p *ByteVectorInputPort) IsVoid() bool
- func (p *ByteVectorInputPort) Read(bs []byte) (int, error)
- func (p *ByteVectorInputPort) ReadByte() (byte, error)
- func (p *ByteVectorInputPort) SchemeString() string
- func (p *ByteVectorInputPort) UnreadByte() error
- type ByteVectorOutputPort
- func (p *ByteVectorOutputPort) Close() error
- func (p *ByteVectorOutputPort) Datum() *bufio.Writer
- func (p *ByteVectorOutputPort) EqualTo(v Value) bool
- func (p *ByteVectorOutputPort) Flush() error
- func (p *ByteVectorOutputPort) IsClosed() bool
- func (p *ByteVectorOutputPort) IsVoid() bool
- func (p *ByteVectorOutputPort) SchemeString() string
- func (p *ByteVectorOutputPort) Write(bs []byte) (int, error)
- func (p *ByteVectorOutputPort) WriteByte(b byte) error
- type Callable
- type Channel
- func (p *Channel) BufferSize() int
- func (p *Channel) Cap() int
- func (p *Channel) Chan() chan Value
- func (p *Channel) Close() error
- func (p *Channel) EqualTo(v Value) bool
- func (p *Channel) ID() uint64
- func (p *Channel) IsClosed() bool
- func (p *Channel) IsVoid() bool
- func (p *Channel) Len() int
- func (p *Channel) Receive() (Value, bool)
- func (p *Channel) SchemeString() string
- func (p *Channel) Send(v Value) error
- func (p *Channel) TryReceive() (Value, bool, bool)
- func (p *Channel) TrySend(v Value) (bool, error)
- type Character
- type CharacterInputPort
- func (p *CharacterInputPort) Close() error
- func (p *CharacterInputPort) Datum() io.RuneReader
- func (p *CharacterInputPort) EqualTo(v Value) bool
- func (p *CharacterInputPort) IsClosed() bool
- func (p *CharacterInputPort) IsVoid() bool
- func (p *CharacterInputPort) Read(bs []byte) (int, error)
- func (p *CharacterInputPort) ReadRune() (rune, int, error)
- func (p *CharacterInputPort) SchemeString() string
- func (p *CharacterInputPort) UnreadRune() error
- type CharacterOutputPort
- func (p *CharacterOutputPort) Close() error
- func (p *CharacterOutputPort) Datum() io.Writer
- func (p *CharacterOutputPort) EqualTo(v Value) bool
- func (p *CharacterOutputPort) Flush() error
- func (p *CharacterOutputPort) IsClosed() bool
- func (p *CharacterOutputPort) IsVoid() bool
- func (p *CharacterOutputPort) SchemeString() string
- func (p *CharacterOutputPort) Write(bs []byte) (int, error)
- func (p *CharacterOutputPort) WriteRune(rn rune) (int, error)
- func (p *CharacterOutputPort) WriteString(s string) (int, error)
- type CompileTimeValue
- type Complex
- func (p *Complex) Abs() Number
- func (p *Complex) Add(o Number) Number
- func (p *Complex) Compare(o Number) int
- func (p *Complex) Datum() complex128
- func (p *Complex) Divide(o Number) (Number, error)
- func (p *Complex) EqualTo(v Value) bool
- func (p *Complex) HashCode() uint64
- func (p *Complex) Imag() float64
- func (p *Complex) ImagPart() Number
- func (p *Complex) IsExact() bool
- func (p *Complex) IsFinite() bool
- func (p *Complex) IsInteger() bool
- func (p *Complex) IsNaN() bool
- func (p *Complex) IsRational() bool
- func (p *Complex) IsReal() bool
- func (p *Complex) IsVoid() bool
- func (p *Complex) IsZero() bool
- func (p *Complex) Kind() NumericKind
- func (p *Complex) LessThan(o Number) bool
- func (p *Complex) Magnitude() float64
- func (p *Complex) Multiply(o Number) Number
- func (p *Complex) Negate() Number
- func (p *Complex) Phase() float64
- func (p *Complex) Real() float64
- func (p *Complex) RealPart() Number
- func (p *Complex) SchemeString() string
- func (p *Complex) Subtract(o Number) Number
- func (p *Complex) ToExact() (Number, error)
- func (p *Complex) ToInexact() Number
- type ComplexNumber
- type ConditionVariable
- func (p *ConditionVariable) Broadcast()
- func (p *ConditionVariable) EqualTo(v Value) bool
- func (p *ConditionVariable) ID() uint64
- func (p *ConditionVariable) IsVoid() bool
- func (p *ConditionVariable) Name() string
- func (p *ConditionVariable) SchemeString() string
- func (p *ConditionVariable) SetSpecific(v Value)
- func (p *ConditionVariable) Signal()
- func (p *ConditionVariable) Specific() Value
- func (p *ConditionVariable) Wait(_ *Mutex, timeout *time.Duration) bool
- func (p *ConditionVariable) WaiterCount() int
- type DebugLocation
- type DebugState
- type Exactness
- type Float
- func (p *Float) Abs() Number
- func (p *Float) Add(o Number) Number
- func (p *Float) Compare(o Number) int
- func (p *Float) Datum() float64
- func (p *Float) Divide(o Number) (Number, error)
- func (p *Float) EqualTo(v Value) bool
- func (p *Float) HashCode() uint64
- func (p *Float) IsExact() bool
- func (p *Float) IsFinite() bool
- func (p *Float) IsInteger() bool
- func (p *Float) IsNaN() bool
- func (p *Float) IsNegative() bool
- func (p *Float) IsPositive() bool
- func (p *Float) IsRational() bool
- func (p *Float) IsVoid() bool
- func (p *Float) IsZero() bool
- func (p *Float) Kind() NumericKind
- func (p *Float) LessThan(o Number) bool
- func (p *Float) Multiply(o Number) Number
- func (p *Float) Negate() Number
- func (p *Float) SchemeString() string
- func (p *Float) Sign() int
- func (p *Float) String() string
- func (p *Float) Subtract(o Number) Number
- func (p *Float) ToExact() (Number, error)
- func (p *Float) ToInexact() Number
- type ForEachFunc
- type Hashable
- type Hashtable
- func (p *Hashtable) Clear()
- func (p *Hashtable) Copy() *Hashtable
- func (p *Hashtable) Delete(key Value) error
- func (p *Hashtable) Entries(fn func(key Hashable, value Value) error) error
- func (p *Hashtable) EqualTo(o Value) bool
- func (p *Hashtable) Get(key Value) (Value, bool, error)
- func (p *Hashtable) HasKey(key Value) (bool, error)
- func (p *Hashtable) IsVoid() bool
- func (p *Hashtable) Keys() Tuple
- func (p *Hashtable) SchemeString() string
- func (p *Hashtable) Set(key Value, val Value) error
- func (p *Hashtable) Size() int
- func (p *Hashtable) Values() Tuple
- type InputOutputPort
- type InputPort
- type Integer
- func (p *Integer) Abs() Number
- func (p *Integer) Add(o Number) Number
- func (p *Integer) Compare(o Number) int
- func (p *Integer) Datum() int64
- func (p *Integer) Divide(o Number) (Number, error)
- func (p *Integer) EqualTo(v Value) bool
- func (p *Integer) HashCode() uint64
- func (p *Integer) IsExact() bool
- func (p *Integer) IsFinite() bool
- func (p *Integer) IsInteger() bool
- func (p *Integer) IsNaN() bool
- func (p *Integer) IsNegative() bool
- func (p *Integer) IsPositive() bool
- func (p *Integer) IsRational() bool
- func (p *Integer) IsVoid() bool
- func (p *Integer) IsZero() bool
- func (p *Integer) Kind() NumericKind
- func (p *Integer) LessThan(o Number) bool
- func (p *Integer) Multiply(o Number) Number
- func (p *Integer) Negate() Number
- func (p *Integer) SchemeString() string
- func (p *Integer) Sign() int
- func (p *Integer) Subtract(o Number) Number
- func (p *Integer) ToExact() (Number, error)
- func (p *Integer) ToInexact() Number
- type JoinTimeoutException
- type Mutex
- func (p *Mutex) EqualTo(v Value) bool
- func (p *Mutex) ID() uint64
- func (p *Mutex) IsVoid() bool
- func (p *Mutex) Lock(timeout *time.Duration, owner *Thread) (bool, error)
- func (p *Mutex) MarkAbandoned()
- func (p *Mutex) Name() string
- func (p *Mutex) Owner() *Thread
- func (p *Mutex) SchemeString() string
- func (p *Mutex) SetSpecific(v Value)
- func (p *Mutex) Specific() Value
- func (p *Mutex) State() MutexState
- func (p *Mutex) StateValue() Value
- func (p *Mutex) Unlock(cv *ConditionVariable, timeout *time.Duration) bool
- type MutexState
- type NamedTypeConstraint
- type NativeError
- func NewErrorObject(message string, irritants ...Value) *NativeError
- func NewErrorObjectWithCause(message string, cause error, irritants ...Value) *NativeError
- func NewErrorObjectWithCauseAndKind(message string, cause error, kind NativeErrorKind, irritants ...Value) *NativeError
- func NewFileError(message string, irritants ...Value) *NativeError
- func NewNativeError(msg string) *NativeError
- func NewReadError(message string, irritants ...Value) *NativeError
- func (p *NativeError) Datum() error
- func (p *NativeError) EqualTo(v Value) bool
- func (p *NativeError) Error() string
- func (p *NativeError) Irritants() Value
- func (p *NativeError) IsFileError() bool
- func (p *NativeError) IsReadError() bool
- func (p *NativeError) IsVoid() bool
- func (p *NativeError) Kind() NativeErrorKind
- func (p *NativeError) Message() *String
- func (p *NativeError) SchemeString() string
- func (p *NativeError) Unwrap() error
- type NativeErrorKind
- type Number
- type NumericKind
- type Once
- type Opaque
- type OpaqueValue
- type OutputPort
- type Pair
- func (p *Pair) Append(vs Value) Value
- func (p *Pair) AsVector() *Vector
- func (p *Pair) Car() Value
- func (p *Pair) Cdr() Value
- func (p *Pair) Datum() [2]Value
- func (p *Pair) EqualTo(o Value) bool
- func (p *Pair) ForEach(ctx context.Context, fn ForEachFunc) (Value, error)
- func (p *Pair) IsEmptyList() bool
- func (p *Pair) IsList() bool
- func (p *Pair) IsVoid() bool
- func (p *Pair) Length() int
- func (p *Pair) SchemeString() string
- func (p *Pair) SetCar(v Value)
- func (p *Pair) SetCdr(v Value)
- func (p *Pair) String() string
- type PairBlock
- type Port
- type Process
- func (p *Process) Cmd() *exec.Cmd
- func (p *Process) Command() string
- func (p *Process) EqualTo(v Value) bool
- func (p *Process) IsVoid() bool
- func (p *Process) SchemeString() string
- func (p *Process) Stderr() *CharacterInputPort
- func (p *Process) Stdin() *CharacterOutputPort
- func (p *Process) Stdout() *CharacterInputPort
- type Promise
- type RWMutex
- func (p *RWMutex) EqualTo(v Value) bool
- func (p *RWMutex) ID() uint64
- func (p *RWMutex) IsVoid() bool
- func (p *RWMutex) Lock()
- func (p *RWMutex) Name() string
- func (p *RWMutex) RLock()
- func (p *RWMutex) RUnlock()
- func (p *RWMutex) SchemeString() string
- func (p *RWMutex) TryLock() bool
- func (p *RWMutex) TryRLock() bool
- func (p *RWMutex) Unlock()
- type Rational
- func (p *Rational) Abs() Number
- func (p *Rational) Add(o Number) Number
- func (p *Rational) Compare(o Number) int
- func (p *Rational) Denom() *big.Int
- func (p *Rational) DenomInt64() int64
- func (p *Rational) Divide(o Number) (Number, error)
- func (p *Rational) EqualTo(v Value) bool
- func (p *Rational) Float64() float64
- func (p *Rational) HashCode() uint64
- func (p *Rational) IsExact() bool
- func (p *Rational) IsFinite() bool
- func (p *Rational) IsInteger() bool
- func (p *Rational) IsNaN() bool
- func (p *Rational) IsNegative() bool
- func (p *Rational) IsPositive() bool
- func (p *Rational) IsRational() bool
- func (p *Rational) IsVoid() bool
- func (p *Rational) IsZero() bool
- func (p *Rational) Kind() NumericKind
- func (p *Rational) LessThan(o Number) bool
- func (p *Rational) Multiply(o Number) Number
- func (p *Rational) Negate() Number
- func (p *Rational) Num() *big.Int
- func (p *Rational) NumInt64() int64
- func (p *Rational) Rat() *big.Rat
- func (p *Rational) SchemeString() string
- func (p *Rational) Sign() int
- func (p *Rational) Subtract(o Number) Number
- func (p *Rational) ToExact() (Number, error)
- func (p *Rational) ToInexact() Number
- type RealNumber
- type Record
- func (p *Record) EqualTo(v Value) bool
- func (p *Record) Field(index int) Value
- func (p *Record) FieldByName(name *Symbol) Value
- func (p *Record) IsVoid() bool
- func (p *Record) RecordType() *RecordType
- func (p *Record) SchemeString() string
- func (p *Record) SetField(index int, value Value)
- func (p *Record) SetFieldByName(name *Symbol, value Value)
- type RecordType
- func (p *RecordType) EqualTo(v Value) bool
- func (p *RecordType) FieldCount() int
- func (p *RecordType) FieldIndex(name *Symbol) int
- func (p *RecordType) FieldNames() []*Symbol
- func (p *RecordType) IsVoid() bool
- func (p *RecordType) Name() *Symbol
- func (p *RecordType) Parent() *RecordType
- func (p *RecordType) SchemeString() string
- type RecordTypeConstraint
- type SchemeWriter
- type SelectCase
- type SelectCaseKind
- type SourceLocation
- type String
- func (p *String) Datum() string
- func (p *String) EqualTo(v Value) bool
- func (p *String) Fill(char rune, start, end int) error
- func (p *String) Get(i int) Value
- func (p *String) HashCode() uint64
- func (p *String) IsImmutable() bool
- func (p *String) IsVoid() bool
- func (p *String) Len() int
- func (p *String) Length() int
- func (p *String) Runes() []rune
- func (p *String) SchemeString() string
- func (p *String) Set(i int, v Value) error
- func (p *String) SetChar(k int, char rune) error
- func (p *String) SetValue(s string) error
- func (p *String) String() string
- type StringInputPort
- func (p *StringInputPort) Close() error
- func (p *StringInputPort) Datum() *bytes.Buffer
- func (p *StringInputPort) EqualTo(v Value) bool
- func (p *StringInputPort) Flush() error
- func (p *StringInputPort) IsClosed() bool
- func (p *StringInputPort) IsVoid() bool
- func (p *StringInputPort) Read(bs []byte) (int, error)
- func (p *StringInputPort) ReadRune() (rune, int, error)
- func (p *StringInputPort) SchemeString() string
- func (p *StringInputPort) String() string
- func (p *StringInputPort) UnreadRune() error
- type StringOutputPort
- func (p *StringOutputPort) Close() error
- func (p *StringOutputPort) Datum() *bytes.Buffer
- func (p *StringOutputPort) EqualTo(v Value) bool
- func (p *StringOutputPort) Flush() error
- func (p *StringOutputPort) IsClosed() bool
- func (p *StringOutputPort) IsVoid() bool
- func (p *StringOutputPort) SchemeString() string
- func (p *StringOutputPort) String() string
- func (p *StringOutputPort) Write(bs []byte) (int, error)
- func (p *StringOutputPort) WriteRune(rn rune) (int, error)
- func (p *StringOutputPort) WriteString(s string) (int, error)
- type Symbol
- type TerminatedThreadException
- type TextualReader
- type TextualWriter
- type Thread
- func (p *Thread) AbandonOwnedMutexes()
- func (p *Thread) Context() context.Context
- func (p *Thread) Done() <-chan struct{}
- func (p *Thread) EqualTo(v Value) bool
- func (p *Thread) ID() uint64
- func (p *Thread) IsVoid() bool
- func (p *Thread) Join(timeout *time.Duration) (Value, error)
- func (p *Thread) Name() string
- func (p *Thread) SchemeString() string
- func (p *Thread) SetSpecific(v Value)
- func (p *Thread) Sleep(d time.Duration)
- func (p *Thread) Specific() Value
- func (p *Thread) Start(parentCtx context.Context) error
- func (p *Thread) State() ThreadState
- func (p *Thread) StateSymbol() *Symbol
- func (p *Thread) Terminate()
- func (p *Thread) TrackMutex(m *Mutex)
- func (p *Thread) UntrackMutex(m *Mutex)
- func (p *Thread) Yield()
- type ThreadState
- type Time
- func (p *Time) Add(d time.Duration) *Time
- func (p *Time) After(other *Time) bool
- func (p *Time) Before(other *Time) bool
- func (p *Time) DurationFromNow() time.Duration
- func (p *Time) EqualTo(v Value) bool
- func (p *Time) GoTime() time.Time
- func (p *Time) IsVoid() bool
- func (p *Time) SchemeString() string
- func (p *Time) Seconds() float64
- func (p *Time) Sub(other *Time) time.Duration
- type Tuple
- type TypeConstraint
- type UncaughtThreadException
- type Value
- type ValueType
- type Vector
- type WaitGroup
- type WriteMode
Constants ¶
const ( PrefixCharacter = `#\` PrefixSyntax = `#'` PrefixDirective = `#!` PrefixBox = `#&` PrefixPrimitive = `#%` PrefixBlockComment = `#|` PrefixLineComment = `;` SpecialEOF = PrefixDirective + `eof` SpecialVoid = PrefixDirective + `void` )
Prefix constants for Scheme value representations.
const DefaultBigFloatPrecision = 256
DefaultBigFloatPrecision is the default precision for BigFloat values.
Variables ¶
var ( // FalseValue is the singleton false boolean. FalseValue = newBoolean(false) // TrueValue is the singleton true boolean. TrueValue = newBoolean(true) )
var ( SymbolMutexNotOwned = NewSymbol("not-owned") SymbolMutexAbandoned = NewSymbol("abandoned") )
Mutex state symbol singletons.
StateValue() returns these instead of allocating fresh symbols on each call. Same process-global vs per-VM identity subtlety as the thread state symbols — see the doc comment on SymbolThreadNew in thread.go for details.
var ( SymbolThreadNew = NewSymbol("new") SymbolThreadRunnable = NewSymbol("runnable") SymbolThreadBlocked = NewSymbol("blocked") SymbolThreadTerminated = NewSymbol("terminated") SymbolThreadUnknown = NewSymbol("unknown") SymbolPrimordial = NewSymbol("primordial") )
Thread state symbol singletons.
StateSymbol() and PrimCurrentThread return these package-level singletons instead of allocating fresh symbols on each call. This guarantees self-consistency: (eq? (thread-state t) (thread-state t)) → #t.
However, these are process-global pointers, not per-VM interned symbols. Reader-interned 'new (created via the parser gate) lives in the per-VM Namespace intern table and is a different pointer. Therefore:
(eq? (thread-state t) (thread-state t)) → #t (same singleton) (eq? (thread-state t) 'new) → #f (singleton ≠ interned) (equal? (thread-state t) 'new) → #t (string comparison)
SRFI-18 defines thread states as symbols but does not mandate eq? identity against reader-interned symbols, so this is conformant. The equal? path works because Symbol.EqualTo compares .Key strings.
To make eq? work against reader-interned symbols, these singletons would need to participate in the per-VM intern table. That requires either:
- Lazily interning on first use (needs access to an environment)
- Registering these symbols during Engine initialization
The values/ package cannot import environment/ (it's lower in the dependency graph), so this would need to be driven from engine.go or registry/. This is deferred until there is a concrete need.
Functions ¶
func BigIntegerEqualsFloat ¶ added in v1.3.0
func BigIntegerEqualsFloat(bi *BigInteger, f *Float) bool
BigIntegerEqualsFloat compares a BigInteger to a Float. Returns true only if the float exactly represents the BigInteger value.
func BooleanToBool ¶ added in v1.4.0
BooleanToBool converts a Scheme *Boolean to a Go bool value.
func DisplayValueToString ¶
DisplayValueToString writes a Scheme value to a string for display with cycle detection. Unlike WriteValueToString, strings are printed without quotes and characters without #\.
func ExactInteger ¶
ExactInteger extracts an exact integer from a Scheme value. Returns the int64 value and true if the value is an exact integer that fits in int64. Returns 0 and false otherwise.
Accepts:
- *Integer: direct int64 value
- *BigInteger: if it fits in int64
- *Rational: if denominator is 1 and numerator fits in int64
R7RS defines exact integers to include rationals like 2/1 that are mathematically integers. Call sites should check for non-negativity if required (e.g., for indexes).
func IntegerEqualsFloat ¶ added in v1.3.0
IntegerEqualsFloat compares an exact integer to an inexact float. Returns true only if the float exactly represents the integer value.
R7RS §6.2.5: Numeric equality must not lose precision. An exact integer and an inexact float are equal only if the float exactly represents the integer's value.
func IsEmptyList ¶
IsEmptyList returns true if the value is the empty list. Returns false for nil values. For Tuple types, delegates to their IsEmptyList method.
func IsList ¶
IsList returns true if the value is a proper list. A proper list is either EmptyList or a chain of pairs ending with EmptyList. Returns false for nil, improper lists (dotted pairs), and non-list values.
func IsVoid ¶
IsVoid returns true if the value represents the absence of a meaningful result.
Void, EmptyList, and nil Semantics ¶
The value system distinguishes three "absence/empty" concepts:
Void (voidType{} singleton): no meaningful result (e.g., set!, display). Canonical check: values.IsVoid(v) — handles both nil and the Void singleton.
EmptyList (emptyListType{} singleton): the empty list () — a valid first-class Scheme value. Implements Tuple but not *Pair. Canonical check: values.IsEmptyList(v) — handles nil safely (returns false).
Go nil (nil interface): uninitialized / absent in Go — not a Scheme value. IsVoid(nil) returns true; IsEmptyList(nil) returns false.
Anti-patterns to avoid:
- v == values.EmptyList or v != values.EmptyList → use values.IsEmptyList(v)
- v == values.Void → use values.IsVoid(v)
- v == nil || values.IsVoid(v) → redundant; values.IsVoid(v) handles nil
Note: typed nil pointers (e.g., var p *Pair = nil) are handled by the type's IsVoid() method, which checks for nil receiver.
func Must ¶ added in v1.1.0
Must panics if err is non-nil or v is not EmptyList. Designed for use with ForEach on lists guaranteed to be proper:
Must(p.ForEach(ctx, func(...) error { ... }))
func NumberToComplex128 ¶ added in v1.5.0
func NumberToComplex128(n Number) complex128
NumberToComplex128 converts any Number to complex128. BigFloat and BigComplex values are reduced to float64/complex128 precision. This is intended for paths where precision loss is acceptable, such as IEEE 754 Inf/NaN guards and inexact complex arithmetic in extensions.
func NumberToFloat64 ¶ added in v1.5.0
NumberToFloat64 converts any Number to a best-effort float64 approximation. BigInteger, BigFloat, and Rational values lose precision in the conversion. For Complex inputs, only the real component is returned; for BigComplex, the real part is converted via toBigFloat. Callers must not rely on this function to reject complex values.
func SchemeTypeName ¶ added in v1.10.3
SchemeTypeName returns the Scheme-facing type name for a value. Used in error messages so users see "integer" instead of "*values.Integer".
func ValidateByteValue ¶ added in v1.3.0
ValidateByteValue checks that an integer is in the byte range [0, 255]. Returns a wrapped werr.ErrNotAByte error if the value is out of range.
func ValueToBool ¶ added in v1.4.0
ValueToBool converts a value into a Go bool using Scheme semantics. In Scheme, only #f is false; everything else (including 0, "", '()) is true.
func WriteSharedValueToString ¶
WriteSharedValueToString writes a Scheme value to a string with shared structure detection. Uses WriteModeWriteShared: datum labels for all multiply-referenced objects. R7RS §6.13.3: write-shared outputs datum labels for all shared structure.
func WriteValueToString ¶
WriteValueToString writes a Scheme value to a string with cycle detection. Uses WriteModeWrite: datum labels only for circular references. R7RS §6.13.3: write outputs datum labels only for objects that are part of a cycle.
Types ¶
type AbandonedMutexException ¶
type AbandonedMutexException struct {
Mutex Value // *Mutex, but avoid circular import
}
AbandonedMutexException is raised when a mutex owner terminates
func (*AbandonedMutexException) Error ¶
func (p *AbandonedMutexException) Error() string
type AtomicBox ¶
type AtomicBox struct {
// contains filtered or unexported fields
}
AtomicBox provides atomic operations on a Value This uses atomic.Value from the standard library
func NewAtomicBox ¶
NewAtomicBox creates a new AtomicBox with the given initial value
func (*AtomicBox) CompareAndSwap ¶
CompareAndSwap atomically compares and swaps if current equals old Returns true if the swap was performed
func (*AtomicBox) SchemeString ¶
SchemeString returns the Scheme representation of the atomic.
type AtomicInt64 ¶
type AtomicInt64 struct {
// contains filtered or unexported fields
}
AtomicInt64 provides atomic operations on int64 values This is more efficient than AtomicBox for integer operations
func NewAtomicInt64 ¶
func NewAtomicInt64(initial int64) *AtomicInt64
NewAtomicInt64 creates a new AtomicInt64 with the given initial value
func (*AtomicInt64) Add ¶
func (p *AtomicInt64) Add(delta int64) int64
Add atomically adds delta and returns the new value
func (*AtomicInt64) CompareAndSwap ¶
func (p *AtomicInt64) CompareAndSwap(ol, nw int64) bool
CompareAndSwap atomically compares and swaps Returns true if the swap was performed
func (*AtomicInt64) EqualTo ¶
func (p *AtomicInt64) EqualTo(v Value) bool
EqualTo returns true if the atomics are the same object.
func (*AtomicInt64) ID ¶
func (p *AtomicInt64) ID() uint64
ID returns the AtomicInt64's unique identifier
func (*AtomicInt64) IsVoid ¶
func (p *AtomicInt64) IsVoid() bool
IsVoid returns true if the atomic int64 is nil.
func (*AtomicInt64) Load ¶
func (p *AtomicInt64) Load() int64
Load atomically loads and returns the value
func (*AtomicInt64) SchemeString ¶
func (p *AtomicInt64) SchemeString() string
SchemeString returns the Scheme representation of the atomic int64.
func (*AtomicInt64) Swap ¶
func (p *AtomicInt64) Swap(nw int64) int64
Swap atomically stores new and returns the old value
type BigComplex ¶
type BigComplex struct {
// contains filtered or unexported fields
}
BigComplex represents an arbitrary-precision complex number. The real and imaginary parts can be *BigInteger, *Rational (exact), or *BigFloat (inexact).
R7RS §6.2.1: Complex numbers are part of the numeric tower hierarchy:
number ⊃ complex ⊃ real ⊃ rational ⊃ integer
R7RS §6.2.2: BigComplex is exact if both parts are BigInteger or Rational, inexact if either part is BigFloat. Operations follow exactness contagion rules.
func NewBigComplex ¶
func NewBigComplex(rel, iam Number) *BigComplex
NewBigComplex creates a new BigComplex from real and imaginary parts. Parts must be *BigInteger, *Rational, or *BigFloat. Other types will panic.
func NewBigComplexFromBigFloats ¶
func NewBigComplexFromBigFloats(rel, iam *BigFloat) *BigComplex
NewBigComplexFromBigFloats creates an inexact BigComplex from BigFloat parts.
func NewBigComplexFromBigIntegers ¶
func NewBigComplexFromBigIntegers(rel, iam *BigInteger) *BigComplex
NewBigComplexFromBigIntegers creates an exact BigComplex from BigInteger parts.
func (*BigComplex) Abs ¶ added in v1.1.0
func (p *BigComplex) Abs() Number
Abs returns the magnitude of this BigComplex as a Number.
R7RS §6.2.6: For complex numbers, abs returns the magnitude.
func (*BigComplex) Add ¶
func (p *BigComplex) Add(o Number) Number
R7RS §6.2.6: The + procedure returns the sum of its arguments. R7RS §6.2.2 Exactness: exact + exact = exact, exact + inexact = inexact. Inexactness is contagious per R7RS §6.2.2.
func (*BigComplex) Compare ¶
func (p *BigComplex) Compare(o Number) int
Compare compares this BigComplex with another number by real parts.
R7RS §6.2.6: Numeric comparisons use mathematical value. For complex numbers, we compare real parts only (matching Complex behavior).
func (*BigComplex) Conjugate ¶
func (p *BigComplex) Conjugate() *BigComplex
Conjugate returns the complex conjugate (a-bi for a+bi).
func (*BigComplex) Divide ¶
func (p *BigComplex) Divide(o Number) (Number, error)
Divide returns the quotient of this BigComplex and another number. Complex division: (a+bi)/(c+di) = ((ac+bd) + (bc-ad)i) / (c²+d²)
R7RS §6.2.6: The / procedure returns the quotient of its arguments. R7RS §6.2.2 Exactness: exact / exact = exact, exact / inexact = inexact.
func (*BigComplex) EqualTo ¶
func (p *BigComplex) EqualTo(o Value) bool
EqualTo returns true if both complex numbers have equal real and imaginary parts.
R7RS §6.2.6: The = procedure compares numerical values for equality.
func (*BigComplex) HashCode ¶ added in v1.5.0
func (p *BigComplex) HashCode() uint64
HashCode returns a hash of the complex value. Hashes real and imaginary parts independently via hashInexactNumeric and combines them with a multiplicative mixing constant. Uses the same combining formula as Complex.HashCode for cross-type consistency: when BigComplex.EqualTo(*Complex) holds, both produce equal hashes.
func (*BigComplex) Imag ¶
func (p *BigComplex) Imag() Number
Imag returns the imaginary part of the complex number.
func (*BigComplex) ImagAsBigFloat ¶
func (p *BigComplex) ImagAsBigFloat() *BigFloat
ImagAsBigFloat returns the imaginary part converted to BigFloat for calculations.
func (*BigComplex) ImagPart ¶ added in v1.1.0
func (p *BigComplex) ImagPart() Number
ImagPart returns the imaginary part of this complex number as a Number.
R7RS §6.2.6: imag-part returns the imaginary part of a complex number.
func (*BigComplex) IsExact ¶
func (p *BigComplex) IsExact() bool
IsExact returns true if both parts are exact (BigInteger or Rational).
R7RS §6.2.2: A complex number is exact if both real and imaginary parts are exact.
func (*BigComplex) IsFinite ¶ added in v1.1.0
func (p *BigComplex) IsFinite() bool
IsFinite returns true if both real and imaginary parts are finite.
R7RS §6.2.6: finite? returns #t if neither part is Inf or NaN.
func (*BigComplex) IsInteger ¶ added in v1.1.0
func (p *BigComplex) IsInteger() bool
IsInteger returns true if the imaginary part is zero and the real part is an integer.
R7RS §6.2.6: integer? returns #t for complex numbers with zero imaginary part whose real part is an integer.
func (*BigComplex) IsNaN ¶ added in v1.1.0
func (p *BigComplex) IsNaN() bool
IsNaN returns true if either real or imaginary part is NaN.
R7RS §6.2.6: nan? returns #t for complex numbers with a NaN component.
func (*BigComplex) IsRational ¶ added in v1.1.0
func (p *BigComplex) IsRational() bool
IsRational returns true if this BigComplex is a real, finite number.
R7RS §6.2.6: rational? returns #t for finite real numbers. Inf and NaN are not rational, even when the imaginary part is zero.
func (*BigComplex) IsReal ¶
func (p *BigComplex) IsReal() bool
IsReal returns true if the imaginary part is zero.
func (*BigComplex) IsVoid ¶
func (p *BigComplex) IsVoid() bool
IsVoid returns true if this BigComplex is nil.
func (*BigComplex) IsZero ¶
func (p *BigComplex) IsZero() bool
IsZero returns true if both real and imaginary parts are zero.
func (*BigComplex) Kind ¶ added in v1.5.0
func (p *BigComplex) Kind() NumericKind
Kind returns the numeric kind for dispatch table indexing.
func (*BigComplex) LessThan ¶
func (p *BigComplex) LessThan(o Number) bool
LessThan compares the real parts of complex numbers. Following R7RS, < is not mathematically defined for complex numbers, but we follow the existing Complex.LessThan pattern of comparing real parts.
func (*BigComplex) Magnitude ¶
func (p *BigComplex) Magnitude() *BigFloat
Magnitude returns the absolute value (modulus) of the complex number. |a+bi| = sqrt(a² + b²)
func (*BigComplex) Multiply ¶
func (p *BigComplex) Multiply(o Number) Number
Multiply returns the product of this BigComplex and another number. Complex multiplication: (a+bi)(c+di) = (ac-bd) + (ad+bc)i
R7RS §6.2.6: The * procedure returns the product of its arguments. R7RS §6.2.2 Exactness: exact * exact = exact, exact * inexact = inexact.
func (*BigComplex) Negate ¶
func (p *BigComplex) Negate() Number
Negate returns the negation of this BigComplex.
func (*BigComplex) Phase ¶
func (p *BigComplex) Phase() *BigFloat
Phase returns the phase (argument) of the complex number in radians. Uses atan2(imag, real).
func (*BigComplex) Real ¶
func (p *BigComplex) Real() Number
Real returns the real part of the complex number.
func (*BigComplex) RealAsBigFloat ¶
func (p *BigComplex) RealAsBigFloat() *BigFloat
RealAsBigFloat returns the real part converted to BigFloat for calculations.
func (*BigComplex) RealPart ¶ added in v1.1.0
func (p *BigComplex) RealPart() Number
RealPart returns the real part of this complex number as a Number.
R7RS §6.2.6: real-part returns the real part of a complex number.
func (*BigComplex) SchemeString ¶
func (p *BigComplex) SchemeString() string
SchemeString returns the Scheme representation of this BigComplex.
func (*BigComplex) Subtract ¶
func (p *BigComplex) Subtract(o Number) Number
Subtract returns the difference of this BigComplex and another number.
R7RS §6.2.6: The - procedure returns the difference of its arguments. R7RS §6.2.2 Exactness: exact - exact = exact, exact - inexact = inexact.
func (*BigComplex) ToExact ¶
func (p *BigComplex) ToExact() (Number, error)
ToExact converts this BigComplex to an exact representation.
R7RS §6.2.6: exact returns an exact representation of its argument. If already exact, returns itself. Otherwise converts BigFloat parts to BigInteger by truncating (may lose precision).
func (*BigComplex) ToInexact ¶
func (p *BigComplex) ToInexact() Number
ToInexact converts this BigComplex to an inexact representation.
R7RS §6.2.6: inexact returns an inexact representation of its argument. Converts BigInteger parts to BigFloat.
type BigFloat ¶
type BigFloat struct {
// contains filtered or unexported fields
}
BigFloat represents an arbitrary-precision floating-point number. Created with the #m prefix in Scheme (e.g., #m3.14159265358979323846).
big.Float natively supports ±Inf via SetInf/IsInf. NaN has no native big.Float representation (operations that produce NaN under IEEE 754 panic with big.ErrNaN instead), so NaN is tracked via an out-of-band flag.
Invariant: when nan is true, value MUST be a valid (zero-valued) *big.Float, never nil, to prevent nil-pointer panics.
func NewBigFloat ¶
NewBigFloat creates a new BigFloat from a big.Float.
func NewBigFloatFromFloat64 ¶
NewBigFloatFromFloat64 creates a new BigFloat from a float64.
func NewBigFloatFromString ¶
NewBigFloatFromString creates a new BigFloat from a string. Returns nil if the string is not a valid number.
func NewBigFloatNaN ¶ added in v1.5.0
func NewBigFloatNaN() *BigFloat
NewBigFloatNaN creates a new BigFloat representing NaN.
func (*BigFloat) Add ¶
R7RS §6.2.6: The + procedure returns the sum of its arguments. R7RS §6.2.2 Exactness: inexact + inexact = inexact, exact + inexact = inexact. Inexactness is contagious per R7RS §6.2.2.
func (*BigFloat) BigFloatValue ¶
BigFloatValue returns the underlying big.Float value.
func (*BigFloat) Compare ¶
Compare compares this BigFloat with another number. Returns 0 for NaN operands (NaN has no valid ordering).
func (*BigFloat) EqualTo ¶
EqualTo returns true if this BigFloat equals another value. NaN is not equal to anything, including itself (IEEE 754).
func (*BigFloat) HashCode ¶ added in v1.3.0
HashCode returns a hash code for this BigFloat. For Inf and NaN, delegates to float64 bit pattern matching Float.HashCode, ensuring Float and BigFloat produce identical hashes for equal values.
Note: NaN != NaN (IEEE 754), so two NaN BigFloats are never EqualTo each other. A NaN key stored in a hashtable is therefore unretrievable — the Hashable contract is not violated, but NaN is not a useful hashtable key.
func (*BigFloat) IsFinite ¶ added in v1.1.0
IsFinite returns true if this BigFloat holds a finite value.
R7RS §6.2.6: finite? returns #t for finite numbers.
func (*BigFloat) IsInteger ¶ added in v1.1.0
IsInteger returns true if this BigFloat represents an integer value.
R7RS §6.2.6: integer? returns #t for inexact integers.
func (*BigFloat) IsNaN ¶ added in v1.1.0
IsNaN returns true if this BigFloat holds NaN.
R7RS §6.2.6: nan? returns #t for NaN values.
func (*BigFloat) IsNegative ¶
IsNegative returns true if this BigFloat is negative. NaN has no sign and returns false.
func (*BigFloat) IsPositive ¶
IsPositive returns true if this BigFloat is positive. NaN has no sign and returns false.
func (*BigFloat) IsRational ¶ added in v1.1.0
IsRational returns true if this BigFloat holds a finite value.
R7RS §6.2.6: rational? returns #t for all finite real numbers. Inf and NaN are not rational.
func (*BigFloat) Kind ¶ added in v1.5.0
func (p *BigFloat) Kind() NumericKind
Kind returns the numeric kind for dispatch table indexing.
func (*BigFloat) SchemeString ¶
SchemeString returns the Scheme representation of this BigFloat.
R7RS §6.2.6: Inexact integers must include a decimal point to distinguish them from exact integers. big.Float.Text('g', -1) drops ".0" for integer values, so we append it when neither '.' nor 'e'/'E' is present.
func (*BigFloat) Sign ¶ added in v1.1.0
Sign returns -1 if negative, 0 if zero, or 1 if positive. NaN returns 0 (NaN has no sign).
func (*BigFloat) Subtract ¶
Subtract returns the difference of this BigFloat and another number.
R7RS §6.2.6: The - procedure returns the difference of its arguments. R7RS §6.2.2 Exactness: inexact - inexact = inexact, exact - inexact = inexact.
type BigInteger ¶
type BigInteger struct {
// contains filtered or unexported fields
}
BigInteger represents an arbitrary-precision integer. Created with the #z prefix in Scheme (e.g., #z12345678901234567890).
R7RS §6.2.1: Integers are exact numbers in the numeric tower hierarchy:
number ⊃ complex ⊃ real ⊃ rational ⊃ integer
R7RS §6.2.2: BigInteger is always exact. Operations on exact numbers produce exact results when mathematically well-defined.
R7RS §6.2.3: Implementations may support arbitrarily large exact integers. BigInteger provides this capability using Go's math/big.Int.
Precision Preservation ¶
BigInteger operations with Float preserve precision by promoting to BigFloat for comparison and arithmetic. This avoids precision loss from converting large BigIntegers to float64 (which has only 53 bits of mantissa precision).
Prior to M5 fix, BigIntegers with >53 significant bits would be truncated when compared with Float, causing incorrect comparison results. For example, comparing 2^53+1 with 2^53.0 would incorrectly report equality after both were converted to the same float64 value.
The fix promotes both operands to BigFloat (arbitrary precision), ensuring correct comparisons and arithmetic while preserving R7RS exactness contagion (exact + inexact → inexact).
func NewBigInteger ¶
func NewBigInteger(v *big.Int) *BigInteger
NewBigInteger creates a new BigInteger from a big.Int.
func NewBigIntegerFromInt64 ¶
func NewBigIntegerFromInt64(v int64) *BigInteger
NewBigIntegerFromInt64 creates a new BigInteger from an int64.
func NewBigIntegerFromString ¶
func NewBigIntegerFromString(s string, base int) *BigInteger
NewBigIntegerFromString creates a new BigInteger from a string. Returns nil if the string is not a valid integer.
func (*BigInteger) Abs ¶
func (p *BigInteger) Abs() Number
Abs returns the absolute value of this BigInteger.
func (*BigInteger) Add ¶
func (p *BigInteger) Add(o Number) Number
R7RS §6.2.6: The + procedure returns the sum of its arguments. R7RS §6.2.2 Exactness: exact + exact = exact (BigInteger), exact + inexact = inexact (Float/Complex). Inexactness is contagious per R7RS §6.2.2.
func (*BigInteger) BigInt ¶
func (p *BigInteger) BigInt() *big.Int
BigInt returns the underlying big.Int value.
func (*BigInteger) Compare ¶
func (p *BigInteger) Compare(o Number) int
Compare compares this BigInteger with another number.
R7RS §6.2.6: Numeric comparisons use mathematical value regardless of exactness. Returns -1, 0, or 1 for less than, equal, or greater than.
func (*BigInteger) Divide ¶
func (p *BigInteger) Divide(o Number) (Number, error)
Divide returns the quotient of this BigInteger and another number.
R7RS §6.2.6: The / procedure returns the quotient of its arguments. For exact arguments, / may return a non-integer (Rational) when the mathematical result is not an integer. Returns BigInteger only when the division is exact (remainder is zero).
R7RS §6.2.2 Exactness: exact / exact = exact (BigInteger or Rational), exact / inexact = inexact (Float or Complex).
func (*BigInteger) EqualTo ¶
func (p *BigInteger) EqualTo(o Value) bool
EqualTo returns true if this BigInteger equals another value.
R7RS §6.2.6: The = procedure compares numerical values for equality. BigInteger also compares equal to Integer when values match.
func (*BigInteger) HashCode ¶
func (p *BigInteger) HashCode() uint64
HashCode returns a hash of the big integer value. Uses the canonical exact-family hash so that Integer, BigInteger, and Rational produce identical hashes for equal values.
func (*BigInteger) Int64 ¶
func (p *BigInteger) Int64() int64
Int64 returns the value as int64 (may overflow for large values).
func (*BigInteger) IsExact ¶
func (p *BigInteger) IsExact() bool
IsExact returns true as BigInteger is always exact.
R7RS §6.2.2: Integers (including BigInteger) are always exact.
func (*BigInteger) IsFinite ¶ added in v1.1.0
func (p *BigInteger) IsFinite() bool
IsFinite returns true since integers are always finite.
R7RS §6.2.6: finite? returns #t for all exact numbers.
func (*BigInteger) IsInteger ¶ added in v1.1.0
func (p *BigInteger) IsInteger() bool
IsInteger returns true since BigInteger is always an integer.
R7RS §6.2.6: integer? returns #t for exact integers.
func (*BigInteger) IsNaN ¶ added in v1.1.0
func (p *BigInteger) IsNaN() bool
IsNaN returns false since integers are never NaN.
R7RS §6.2.6: nan? returns #f for exact numbers.
func (*BigInteger) IsNegative ¶
func (p *BigInteger) IsNegative() bool
IsNegative returns true if this BigInteger is negative.
func (*BigInteger) IsPositive ¶
func (p *BigInteger) IsPositive() bool
IsPositive returns true if this BigInteger is positive.
func (*BigInteger) IsRational ¶ added in v1.1.0
func (p *BigInteger) IsRational() bool
IsRational returns true since integers are a subset of rationals.
R7RS §6.2.6: rational? returns #t for all real finite numbers.
func (*BigInteger) IsVoid ¶
func (p *BigInteger) IsVoid() bool
IsVoid returns true if this BigInteger is nil.
func (*BigInteger) IsZero ¶
func (p *BigInteger) IsZero() bool
IsZero returns true if this BigInteger is zero.
func (*BigInteger) Kind ¶ added in v1.5.0
func (p *BigInteger) Kind() NumericKind
Add returns the sum of this BigInteger and another number.
Kind returns the numeric kind for dispatch table indexing.
func (*BigInteger) LessThan ¶
func (p *BigInteger) LessThan(o Number) bool
LessThan returns true if this BigInteger is less than another number.
R7RS §6.2.6: The < procedure returns #t if its arguments are monotonically increasing. Comparison across numeric types uses mathematical value.
func (*BigInteger) Multiply ¶
func (p *BigInteger) Multiply(o Number) Number
Multiply returns the product of this BigInteger and another number.
R7RS §6.2.6: The * procedure returns the product of its arguments. R7RS §6.2.2 Exactness: exact * exact = exact, exact * inexact = inexact. Exception: Exact zero dominates—(* 0 x) may return exact 0 even when x is inexact. Zero is an exact value when the result is mathematically unambiguous. This implementation follows Chez Scheme's behavior.
func (*BigInteger) Negate ¶
func (p *BigInteger) Negate() Number
Negate returns the negation of this BigInteger.
func (*BigInteger) SchemeString ¶
func (p *BigInteger) SchemeString() string
SchemeString returns the Scheme representation of this BigInteger.
func (*BigInteger) Sign ¶ added in v1.1.0
func (p *BigInteger) Sign() int
Sign returns -1 if negative, 0 if zero, or 1 if positive.
func (*BigInteger) Subtract ¶
func (p *BigInteger) Subtract(o Number) Number
Subtract returns the difference of this BigInteger and another number.
R7RS §6.2.6: The - procedure returns the difference of its arguments. R7RS §6.2.2 Exactness: exact - exact = exact, exact - inexact = inexact.
func (*BigInteger) ToExact ¶
func (p *BigInteger) ToExact() (Number, error)
ToExact returns this BigInteger as an exact number.
R7RS §6.2.6: exact returns an exact representation of its argument. Since BigInteger is already exact, it returns itself.
func (*BigInteger) ToInexact ¶
func (p *BigInteger) ToInexact() Number
ToInexact returns this BigInteger converted to an inexact float.
R7RS §6.2.6: inexact returns an inexact representation of its argument. Converts to Float (float64), which may lose precision for large values.
R7RS §6.2.3: The inexact representation may have limited precision, but the conversion should be as close as practical.
PRECISION NOTE: For BigIntegers with more than 53 significant bits, precision is lost when converting to float64 (IEEE 754 binary64 has only 53 bits of mantissa precision). This is compliant with R7RS which allows inexact to be approximate.
type BinaryInputPort ¶
type BinaryInputPort struct {
// contains filtered or unexported fields
}
BinaryInputPort represents a Scheme binary input port.
func NewBinaryInputPort ¶
func NewBinaryInputPort(rdr *bufio.Reader) *BinaryInputPort
NewBinaryInputPort creates a new binary input port wrapping the given rdr.
func NewBinaryInputPortFromReader ¶
func NewBinaryInputPortFromReader(reader io.Reader) *BinaryInputPort
NewBinaryInputPortFromReader creates a new input port reading from the given byte slice.
func (*BinaryInputPort) Close ¶
func (p *BinaryInputPort) Close() error
Close marks the port as closed and, if a closer was provided, closes the underlying stream. Close is idempotent.
func (*BinaryInputPort) Datum ¶
func (p *BinaryInputPort) Datum() io.Reader
Datum returns the underlying io.Reader.
func (*BinaryInputPort) EqualTo ¶
EqualTo returns true if v is a port with the same kind and datum identity. This works because Go's any equality checks both dynamic type and value, so two ports sharing a kind but using different backing types (e.g., *bufio.Writer vs *bytes.Buffer) will never compare equal.
func (*BinaryInputPort) IsClosed ¶
func (p *BinaryInputPort) IsClosed() bool
IsClosed returns true if the port has been closed.
func (*BinaryInputPort) IsVoid ¶
func (p *BinaryInputPort) IsVoid() bool
IsVoid returns true if the port is nil.
func (*BinaryInputPort) ReadByte ¶
func (p *BinaryInputPort) ReadByte() (byte, error)
func (*BinaryInputPort) SchemeString ¶
func (p *BinaryInputPort) SchemeString() string
SchemeString returns the Scheme external representation of the port.
func (*BinaryInputPort) UnreadByte ¶
func (p *BinaryInputPort) UnreadByte() error
type BinaryOutputPort ¶
type BinaryOutputPort struct {
// contains filtered or unexported fields
}
BinaryOutputPort represents a Scheme binary output port.
func NewBinaryOutputPortFromWriter ¶
func NewBinaryOutputPortFromWriter(writer io.Writer) *BinaryOutputPort
NewBinaryOutputPortFromWriter creates a new input port reading from the given byte slice.
func (*BinaryOutputPort) Close ¶
func (p *BinaryOutputPort) Close() error
Close flushes buffered data and closes the underlying stream.
func (*BinaryOutputPort) Datum ¶
func (p *BinaryOutputPort) Datum() io.Writer
Datum returns the underlying io.Writer.
func (*BinaryOutputPort) EqualTo ¶
EqualTo returns true if v is a port with the same kind and datum identity. This works because Go's any equality checks both dynamic type and value, so two ports sharing a kind but using different backing types (e.g., *bufio.Writer vs *bytes.Buffer) will never compare equal.
func (*BinaryOutputPort) Flush ¶
func (p *BinaryOutputPort) Flush() error
Flush flushes the port's buffer.
func (*BinaryOutputPort) IsClosed ¶
func (p *BinaryOutputPort) IsClosed() bool
IsClosed returns true if the port has been closed.
func (*BinaryOutputPort) IsVoid ¶
func (p *BinaryOutputPort) IsVoid() bool
IsVoid returns true if the port is nil.
func (*BinaryOutputPort) SchemeString ¶
func (p *BinaryOutputPort) SchemeString() string
SchemeString returns the Scheme external representation of the port.
func (*BinaryOutputPort) Write ¶
func (p *BinaryOutputPort) Write(bs []byte) (int, error)
Write writes bytes to the port.
func (*BinaryOutputPort) WriteByte ¶
func (p *BinaryOutputPort) WriteByte(b byte) error
WriteByte writes a single byte to the port.
type BinaryReader ¶
BinaryReader represents a binary input port capable of byte-level I/O.
R7RS §6.13.2: Binary input ports support read-u8, peek-u8, read-bytevector, etc.
type BinaryWriter ¶
type BinaryWriter interface {
OutputPort
WriteByte(byte) error
}
BinaryWriter represents a binary output port capable of byte-level I/O.
R7RS §6.13.3: Binary output ports support write-u8, write-bytevector, etc.
type Boolean ¶
type Boolean struct {
Value bool
}
Boolean represents a Scheme boolean value.
func BoolToBoolean ¶ added in v1.4.0
BoolToBoolean converts a Go bool to a Scheme boolean value.
func ValueToBoolean ¶ added in v1.4.0
ValueToBoolean converts a value into a Scheme *Boolean using Scheme semantics.
func (*Boolean) SchemeString ¶
SchemeString returns the Scheme representation of the boolean.
type Box ¶
type Box struct {
Value Value
}
Box represents a mutable Scheme box (container).
func (*Box) SchemeString ¶
SchemeString returns the Scheme representation of the box.
type Byte ¶
type Byte struct {
Value uint8
}
Byte represents a Scheme byte value (0-255).
func (*Byte) SchemeString ¶
SchemeString returns the Scheme representation of the byte.
type ByteVector ¶
type ByteVector []*Byte
ByteVector represents a Scheme bytevector.
func NewByteVector ¶
func NewByteVector(vs ...*Byte) *ByteVector
NewByteVector creates a new bytevector from byte values.
func NewByteVectorFromBytes ¶
func NewByteVectorFromBytes(vs ...byte) *ByteVector
func NewByteVectorFromIntegers ¶
func NewByteVectorFromIntegers(vs ...*Integer) (*ByteVector, error)
NewByteVectorFromIntegers creates a new bytevector from integer values. Each integer must be in the range [0, 255] per R7RS §6.4.
func (*ByteVector) AsBytes ¶
func (p *ByteVector) AsBytes(is ...int) []byte
AsBytes converts the bytevector to a Go byte slice. The starti and endi parameters specify the range of bytes to include. If starti is negative, it is treated as 0. If endi is greater than the length of the bytevector or non-positive, it is treated as the length of the bytevector. If starti is greater than endi, it is treated as equal to endi.
func (*ByteVector) AsList ¶
func (p *ByteVector) AsList() Tuple
AsList converts the vector to a proper list (linked list of pairs). Returns void (nil Pair) if the vector is void. Returns EmptyList if the vector is empty. Otherwise returns a newly constructed list containing the vector's elements.
func (*ByteVector) Datum ¶
func (p *ByteVector) Datum() []*Byte
Datum returns the underlying byte slice.
func (*ByteVector) EqualTo ¶
func (p *ByteVector) EqualTo(v Value) bool
EqualTo returns true if the bytevectors have equal contents.
func (*ByteVector) Get ¶
func (p *ByteVector) Get(i int) Value
func (*ByteVector) IsVoid ¶
func (p *ByteVector) IsVoid() bool
IsVoid returns true if the bytevector is nil.
func (*ByteVector) Length ¶
func (p *ByteVector) Length() int
func (*ByteVector) SchemeString ¶
func (p *ByteVector) SchemeString() string
SchemeString returns the Scheme representation of the bytevector.
type ByteVectorBufferedOutputPort ¶ added in v1.5.0
type ByteVectorBufferedOutputPort struct {
// contains filtered or unexported fields
}
ByteVectorBufferedOutputPort represents a Scheme output port writing to memory.
func NewByteVectorBufferedOutputPort ¶ added in v1.5.0
func NewByteVectorBufferedOutputPort() *ByteVectorBufferedOutputPort
NewByteVectorBufferedOutputPort creates a new in-memory bytevector output port.
func NewByteVectorBufferedOutputPortFromBuffer ¶ added in v1.5.0
func NewByteVectorBufferedOutputPortFromBuffer(buf *bytes.Buffer) *ByteVectorBufferedOutputPort
NewByteVectorBufferedOutputPortFromBuffer creates a new in-memory bytevector output port.
func (*ByteVectorBufferedOutputPort) Close ¶ added in v1.5.0
func (p *ByteVectorBufferedOutputPort) Close() error
Close marks the port as closed and, if a closer was provided, closes the underlying stream. Close is idempotent.
func (*ByteVectorBufferedOutputPort) Datum ¶ added in v1.5.0
func (p *ByteVectorBufferedOutputPort) Datum() *bytes.Buffer
Datum returns the underlying bytes.Buffer.
func (*ByteVectorBufferedOutputPort) EqualTo ¶ added in v1.5.0
EqualTo returns true if v is a port with the same kind and datum identity. This works because Go's any equality checks both dynamic type and value, so two ports sharing a kind but using different backing types (e.g., *bufio.Writer vs *bytes.Buffer) will never compare equal.
func (*ByteVectorBufferedOutputPort) Flush ¶ added in v1.5.0
func (p *ByteVectorBufferedOutputPort) Flush() error
func (*ByteVectorBufferedOutputPort) IsClosed ¶ added in v1.5.0
func (p *ByteVectorBufferedOutputPort) IsClosed() bool
IsClosed returns true if the port has been closed.
func (*ByteVectorBufferedOutputPort) IsVoid ¶ added in v1.5.0
func (p *ByteVectorBufferedOutputPort) IsVoid() bool
IsVoid returns true if the port is nil.
func (*ByteVectorBufferedOutputPort) ReadByteVector ¶ added in v1.5.0
func (p *ByteVectorBufferedOutputPort) ReadByteVector() (*ByteVector, error)
func (*ByteVectorBufferedOutputPort) SchemeString ¶ added in v1.5.0
func (p *ByteVectorBufferedOutputPort) SchemeString() string
SchemeString returns the Scheme external representation of the port.
func (*ByteVectorBufferedOutputPort) Write ¶ added in v1.5.0
func (p *ByteVectorBufferedOutputPort) Write(bs []byte) (int, error)
func (*ByteVectorBufferedOutputPort) WriteByte ¶ added in v1.5.0
func (p *ByteVectorBufferedOutputPort) WriteByte(b byte) error
type ByteVectorExtractor ¶
type ByteVectorExtractor interface {
ReadByteVector() (*ByteVector, error)
}
ByteVectorExtractor represents a port that can extract its accumulated bytes.
type ByteVectorInputOutputPort ¶
type ByteVectorInputOutputPort struct {
// contains filtered or unexported fields
}
ByteVectorInputOutputPort represents a Scheme output port writing to memory.
func NewByteVectorInputOutputPort ¶
func NewByteVectorInputOutputPort() *ByteVectorInputOutputPort
NewByteVectorInputOutputPort creates a new in-memory bytevector output port.
func NewByteVectorInputOutputPortFromBuffer ¶
func NewByteVectorInputOutputPortFromBuffer(buf *bytes.Buffer) *ByteVectorInputOutputPort
NewByteVectorInputOutputPortFromBuffer creates a new in-memory bytevector output port.
func (*ByteVectorInputOutputPort) Close ¶
func (p *ByteVectorInputOutputPort) Close() error
Close marks the port as closed and, if a closer was provided, closes the underlying stream. Close is idempotent.
func (*ByteVectorInputOutputPort) Datum ¶
func (p *ByteVectorInputOutputPort) Datum() *bytes.Buffer
Datum returns the underlying bytes.Buffer.
func (*ByteVectorInputOutputPort) EqualTo ¶
EqualTo returns true if v is a port with the same kind and datum identity. This works because Go's any equality checks both dynamic type and value, so two ports sharing a kind but using different backing types (e.g., *bufio.Writer vs *bytes.Buffer) will never compare equal.
func (*ByteVectorInputOutputPort) Flush ¶
func (p *ByteVectorInputOutputPort) Flush() error
func (*ByteVectorInputOutputPort) IsClosed ¶
func (p *ByteVectorInputOutputPort) IsClosed() bool
IsClosed returns true if the port has been closed.
func (*ByteVectorInputOutputPort) IsVoid ¶
func (p *ByteVectorInputOutputPort) IsVoid() bool
IsVoid returns true if the port is nil.
func (*ByteVectorInputOutputPort) Read ¶
func (p *ByteVectorInputOutputPort) Read(bs []byte) (int, error)
func (*ByteVectorInputOutputPort) ReadByte ¶
func (p *ByteVectorInputOutputPort) ReadByte() (byte, error)
func (*ByteVectorInputOutputPort) ReadByteVector ¶
func (p *ByteVectorInputOutputPort) ReadByteVector() (*ByteVector, error)
func (*ByteVectorInputOutputPort) SchemeString ¶
func (p *ByteVectorInputOutputPort) SchemeString() string
SchemeString returns the Scheme external representation of the port.
func (*ByteVectorInputOutputPort) UnreadByte ¶
func (p *ByteVectorInputOutputPort) UnreadByte() error
UnreadByte unreads the last byte read, allowing it to be read again.
func (*ByteVectorInputOutputPort) Write ¶
func (p *ByteVectorInputOutputPort) Write(bs []byte) (int, error)
func (*ByteVectorInputOutputPort) WriteByte ¶
func (p *ByteVectorInputOutputPort) WriteByte(b byte) error
type ByteVectorInputPort ¶
type ByteVectorInputPort struct {
// contains filtered or unexported fields
}
ByteVectorInputPort represents a Scheme input port reading from a byte slice.
func NewByteVectorInputPortFromReader ¶
func NewByteVectorInputPortFromReader(reader io.Reader) *ByteVectorInputPort
NewByteVectorInputPortFromReader creates a new input port reading from the given byte slice.
func (*ByteVectorInputPort) Close ¶
func (p *ByteVectorInputPort) Close() error
Close marks the port as closed and, if a closer was provided, closes the underlying stream. Close is idempotent.
func (*ByteVectorInputPort) Datum ¶
func (p *ByteVectorInputPort) Datum() *bufio.Reader
Datum returns the underlying bytes.Reader.
func (*ByteVectorInputPort) EqualTo ¶
EqualTo returns true if v is a port with the same kind and datum identity. This works because Go's any equality checks both dynamic type and value, so two ports sharing a kind but using different backing types (e.g., *bufio.Writer vs *bytes.Buffer) will never compare equal.
func (*ByteVectorInputPort) IsClosed ¶
func (p *ByteVectorInputPort) IsClosed() bool
IsClosed returns true if the port has been closed.
func (*ByteVectorInputPort) IsVoid ¶
func (p *ByteVectorInputPort) IsVoid() bool
IsVoid returns true if the port is nil.
func (*ByteVectorInputPort) ReadByte ¶
func (p *ByteVectorInputPort) ReadByte() (byte, error)
ReadByte reads and returns the next byte from the port.
func (*ByteVectorInputPort) SchemeString ¶
func (p *ByteVectorInputPort) SchemeString() string
SchemeString returns the Scheme external representation of the port.
func (*ByteVectorInputPort) UnreadByte ¶
func (p *ByteVectorInputPort) UnreadByte() error
UnreadByte unreads the last byte read, allowing it to be read again.
type ByteVectorOutputPort ¶
type ByteVectorOutputPort struct {
// contains filtered or unexported fields
}
ByteVectorOutputPort represents a Scheme output port writing to memory.
func NewByteVectorOutputPortFromWriter ¶
func NewByteVectorOutputPortFromWriter(wrt io.Writer) *ByteVectorOutputPort
NewByteVectorOutputPortFromWriter creates a new in-memory bytevector output port.
func (*ByteVectorOutputPort) Close ¶
func (p *ByteVectorOutputPort) Close() error
Close flushes buffered data and closes the underlying stream.
func (*ByteVectorOutputPort) Datum ¶
func (p *ByteVectorOutputPort) Datum() *bufio.Writer
Datum returns the underlying bytes.Buffer.
func (*ByteVectorOutputPort) EqualTo ¶
EqualTo returns true if v is a port with the same kind and datum identity. This works because Go's any equality checks both dynamic type and value, so two ports sharing a kind but using different backing types (e.g., *bufio.Writer vs *bytes.Buffer) will never compare equal.
func (*ByteVectorOutputPort) Flush ¶
func (p *ByteVectorOutputPort) Flush() error
func (*ByteVectorOutputPort) IsClosed ¶
func (p *ByteVectorOutputPort) IsClosed() bool
IsClosed returns true if the port has been closed.
func (*ByteVectorOutputPort) IsVoid ¶
func (p *ByteVectorOutputPort) IsVoid() bool
IsVoid returns true if the port is nil.
func (*ByteVectorOutputPort) SchemeString ¶
func (p *ByteVectorOutputPort) SchemeString() string
SchemeString returns the Scheme external representation of the port.
func (*ByteVectorOutputPort) WriteByte ¶
func (p *ByteVectorOutputPort) WriteByte(b byte) error
type Callable ¶ added in v1.5.0
Callable represents a Scheme procedure — any value that can be applied to arguments.
R7RS §6.1: The procedure? predicate returns #t for all callable types. This includes lambdas, case-lambdas, parameter objects (R7RS §4.2.6), and composable continuations.
AcceptsArity reports whether the procedure can be called with exactly n arguments. This captures arity constraints that are otherwise scattered across per-type checks in the VM apply path.
Implemented by: MachineClosure, CaseLambdaClosure, Parameter, ComposableContinuation.
type Channel ¶
type Channel struct {
// contains filtered or unexported fields
}
Channel represents a Go channel exposed to Scheme
func NewChannel ¶
NewChannel creates a new channel with the given buffer size bufferSize of 0 creates an unbuffered channel
func (*Channel) BufferSize ¶
BufferSize returns the channel's buffer size
func (*Channel) Receive ¶
Receive receives a value from the channel (blocking) Returns the value and true, or nil and false if channel is closed
func (*Channel) SchemeString ¶
SchemeString returns the Scheme representation of this channel.
func (*Channel) TryReceive ¶
TryReceive attempts to receive a value without blocking Returns (value, true, true) if received Returns (nil, false, true) if would block Returns (nil, false, false) if channel is closed
type Character ¶
type Character struct {
Value rune
}
Character represents a Scheme character value.
func NewCharacter ¶
NewCharacter creates a new character from a rune.
func (*Character) SchemeString ¶
SchemeString returns the Scheme representation of the character. Named characters use the R7RS mnemonic form (#\newline). Graphic characters use #\<char>. Non-graphic non-named characters use #\xHEX for round-trip safety.
type CharacterInputPort ¶
type CharacterInputPort struct {
// contains filtered or unexported fields
}
CharacterInputPort represents a Scheme textual input port.
func NewCharacterInputPort ¶
func NewCharacterInputPort(rdr *bufio.Reader) *CharacterInputPort
NewCharacterInputPort creates a new character input port from an io.RuneReader.
func NewCharacterInputPortFromReader ¶
func NewCharacterInputPortFromReader(rdr io.Reader) *CharacterInputPort
NewCharacterInputPortFromReader creates a new character input port from an io.Reader.
func (*CharacterInputPort) Close ¶
func (p *CharacterInputPort) Close() error
Close marks the port as closed and, if a closer was provided, closes the underlying stream. Close is idempotent.
func (*CharacterInputPort) Datum ¶
func (p *CharacterInputPort) Datum() io.RuneReader
Datum returns the underlying io.RuneReader.
func (*CharacterInputPort) EqualTo ¶
EqualTo returns true if v is a port with the same kind and datum identity. This works because Go's any equality checks both dynamic type and value, so two ports sharing a kind but using different backing types (e.g., *bufio.Writer vs *bytes.Buffer) will never compare equal.
func (*CharacterInputPort) IsClosed ¶
func (p *CharacterInputPort) IsClosed() bool
IsClosed returns true if the port has been closed.
func (*CharacterInputPort) IsVoid ¶
func (p *CharacterInputPort) IsVoid() bool
IsVoid returns true if the port is nil.
func (*CharacterInputPort) SchemeString ¶
func (p *CharacterInputPort) SchemeString() string
SchemeString returns the Scheme external representation of the port.
func (*CharacterInputPort) UnreadRune ¶
func (p *CharacterInputPort) UnreadRune() error
type CharacterOutputPort ¶
type CharacterOutputPort struct {
// contains filtered or unexported fields
}
CharacterOutputPort represents a Scheme textual output port.
func NewCharacterOutputPortFromWriter ¶
func NewCharacterOutputPortFromWriter(wrt io.Writer) *CharacterOutputPort
NewCharacterOutputPortFromWriter creates a new character output port wrapping the given buf.
func (*CharacterOutputPort) Close ¶
func (p *CharacterOutputPort) Close() error
Close flushes buffered data and closes the underlying stream.
func (*CharacterOutputPort) Datum ¶
func (p *CharacterOutputPort) Datum() io.Writer
Datum returns the underlying data of the CharacterOutputPort as an io.Writer. there is no RunWriter interface in the standard library, so we just use io.Writer here.
func (*CharacterOutputPort) EqualTo ¶
EqualTo returns true if v is a port with the same kind and datum identity. This works because Go's any equality checks both dynamic type and value, so two ports sharing a kind but using different backing types (e.g., *bufio.Writer vs *bytes.Buffer) will never compare equal.
func (*CharacterOutputPort) Flush ¶
func (p *CharacterOutputPort) Flush() error
func (*CharacterOutputPort) IsClosed ¶
func (p *CharacterOutputPort) IsClosed() bool
IsClosed returns true if the port has been closed.
func (*CharacterOutputPort) IsVoid ¶
func (p *CharacterOutputPort) IsVoid() bool
IsVoid returns true if the port is nil.
func (*CharacterOutputPort) SchemeString ¶
func (p *CharacterOutputPort) SchemeString() string
SchemeString returns the Scheme external representation of the port.
func (*CharacterOutputPort) WriteRune ¶
func (p *CharacterOutputPort) WriteRune(rn rune) (int, error)
WriteRune writes a single rune to the port's buf.
func (*CharacterOutputPort) WriteString ¶
func (p *CharacterOutputPort) WriteString(s string) (int, error)
type CompileTimeValue ¶
type CompileTimeValue struct {
Value Value
}
CompileTimeValue wraps a value that is stored in the expand phase but accessible during macro expansion. This enables compile-time computation via define-for-syntax and begin-for-syntax.
func NewCompileTimeValue ¶
func NewCompileTimeValue(v Value) *CompileTimeValue
NewCompileTimeValue creates a new compile-time value.
func (*CompileTimeValue) EqualTo ¶
func (p *CompileTimeValue) EqualTo(v Value) bool
EqualTo returns true if the compile-time values are equal.
func (*CompileTimeValue) IsVoid ¶
func (p *CompileTimeValue) IsVoid() bool
IsVoid returns true if the compile-time value is nil.
func (*CompileTimeValue) SchemeString ¶
func (p *CompileTimeValue) SchemeString() string
SchemeString returns the Scheme representation of the compile-time value.
func (*CompileTimeValue) Unwrap ¶
func (p *CompileTimeValue) Unwrap() Value
Unwrap returns the underlying value.
type Complex ¶
type Complex struct {
Value complex128
}
Complex represents a Scheme complex number.
func NewComplex ¶
func NewComplex(v complex128) *Complex
NewComplex creates a new complex number from a complex128 value.
func NewComplexFromParts ¶
NewComplexFromParts creates a new complex number from real and imaginary parts.
func (*Complex) Abs ¶ added in v1.1.0
Abs returns the magnitude of this complex number.
R7RS §6.2.6: For complex numbers, abs returns the magnitude.
func (*Complex) Add ¶
Add returns the sum of this complex number and another number. Zero short-circuit: 0+x=x preserves exactness per R7RS §6.2.2.
func (*Complex) Compare ¶
Compare compares this complex number with another number by real parts.
R7RS §6.2.6: Complex comparison compares real parts only. Returns -1 if p < o, 0 if p == o, 1 if p > o.
func (*Complex) Datum ¶
func (p *Complex) Datum() complex128
Datum returns the underlying complex128 value.
func (*Complex) HashCode ¶ added in v1.5.0
HashCode returns a hash of the complex value. Hashes real and imaginary parts independently via hashComplexComponent and combines them with a multiplicative mixing constant. NaN and ±Inf components use bitwise hashing to avoid big.Float panics.
func (*Complex) ImagPart ¶ added in v1.1.0
ImagPart returns the imaginary part of this complex number as a Number.
R7RS §6.2.6: imag-part returns the imaginary part of a complex number.
func (*Complex) IsExact ¶
IsExact returns false since Complex is always inexact.
R7RS §6.2.2: Complex numbers with floating-point components are inexact.
func (*Complex) IsFinite ¶ added in v1.1.0
IsFinite returns true if both real and imaginary parts are finite.
R7RS §6.2.6: finite? returns #t if neither part is Inf or NaN.
func (*Complex) IsInteger ¶ added in v1.1.0
IsInteger returns true if this complex has zero imaginary part and an integer real part.
R7RS §6.2.6: integer? returns #t for complex numbers with zero imaginary part whose real part is an integer.
func (*Complex) IsNaN ¶ added in v1.1.0
IsNaN returns true if either the real or imaginary part is NaN.
R7RS §6.2.6: nan? returns #t if any component is NaN.
func (*Complex) IsRational ¶ added in v1.1.0
IsRational returns true if the imaginary part is zero and the real part is finite.
R7RS §6.2.6: A complex number with zero imaginary part is rational if its real part is a finite real number.
func (*Complex) Kind ¶ added in v1.5.0
func (p *Complex) Kind() NumericKind
Kind returns the numeric kind for dispatch table indexing.
func (*Complex) Negate ¶
Negate returns the negation of this complex number.
R7RS §6.2.6: The - procedure with one argument returns the additive inverse.
func (*Complex) RealPart ¶ added in v1.1.0
RealPart returns the real part of this complex number as a Number.
R7RS §6.2.6: real-part returns the real part of a complex number.
func (*Complex) SchemeString ¶
SchemeString returns the Scheme representation of this complex number. R7RS §6.2.6: Ensures decimal point for inexact values, lowercase inf/nan.
func (*Complex) Subtract ¶
Subtract returns the difference of this complex number and another number.
type ComplexNumber ¶ added in v1.1.0
ComplexNumber represents a complex-valued number with accessible parts.
R7RS §6.2.6: Complex numbers have real and imaginary parts accessible via real-part and imag-part.
type ConditionVariable ¶
type ConditionVariable struct {
// contains filtered or unexported fields
}
ConditionVariable represents a Scheme condition variable (SRFI-18)
func NewConditionVariable ¶
func NewConditionVariable(name string) *ConditionVariable
NewConditionVariable creates a new condition variable
func (*ConditionVariable) Broadcast ¶
func (p *ConditionVariable) Broadcast()
Broadcast wakes all waiting threads.
func (*ConditionVariable) EqualTo ¶
func (p *ConditionVariable) EqualTo(v Value) bool
EqualTo returns true if the condition variables are the same object.
func (*ConditionVariable) ID ¶
func (p *ConditionVariable) ID() uint64
ID returns the condition variable's unique identifier
func (*ConditionVariable) IsVoid ¶
func (p *ConditionVariable) IsVoid() bool
IsVoid returns true if the condition variable is nil.
func (*ConditionVariable) Name ¶
func (p *ConditionVariable) Name() string
Name returns the condition variable's name
func (*ConditionVariable) SchemeString ¶
func (p *ConditionVariable) SchemeString() string
SchemeString returns the Scheme representation of this condition variable.
func (*ConditionVariable) SetSpecific ¶
func (p *ConditionVariable) SetSpecific(v Value)
SetSpecific sets the condition variable's specific field
func (*ConditionVariable) Signal ¶
func (p *ConditionVariable) Signal()
Signal wakes one waiting thread (FIFO order).
func (*ConditionVariable) Specific ¶
func (p *ConditionVariable) Specific() Value
Specific returns the condition variable's specific field
func (*ConditionVariable) Wait ¶
func (p *ConditionVariable) Wait(_ *Mutex, timeout *time.Duration) bool
Wait waits on the condition variable. Returns true if signaled, false if timeout.
Each waiter registers a per-waiter channel. Signal/Broadcast close the channel to wake the waiter. Timeouts remove the channel from the queue without disturbing other waiters.
func (*ConditionVariable) WaiterCount ¶
func (p *ConditionVariable) WaiterCount() int
WaiterCount returns the number of threads waiting on this condition variable.
type DebugLocation ¶ added in v1.13.14
DebugLocation holds file/line/column for debug and error display. This is a simple struct for presentation layers (REPL, debugger UI), distinct from the SourceLocation interface which is a full Value type used by procedure-source-location.
type DebugState ¶ added in v1.13.14
type DebugState interface {
// CurrentLocation returns the source location at the current
// execution point, or nil if no source info is available.
CurrentLocation() *DebugLocation
// FormatStackTrace returns a human-readable stack trace string,
// walking at most maxDepth frames.
FormatStackTrace(maxDepth int) string
}
DebugState provides read-only access to VM execution state. Implemented by the VM's MachineContext; consumed by presentation layers (REPL, debugger UI) without importing machine/.
type Exactness ¶
type Exactness int
Exactness represents whether a number is exact or inexact.
R7RS §6.2.2: Numbers are either exact or inexact. A number is exact if it was written as an exact constant or derived from exact numbers using only exact operations. Otherwise, it is inexact.
func ExactnessOf ¶
ExactnessOf returns the exactness of a number.
R7RS §6.2.2: - Integer, BigInteger, Rational are exact - Float, BigFloat, Complex are inexact - BigComplex depends on its components
type Float ¶
type Float struct {
Value float64
}
Float represents a Scheme floating-point number.
func (*Float) Add ¶
R7RS §6.2.6: The + procedure returns the sum of its arguments. R7RS §6.2.2 Exactness: inexact + inexact = inexact, exact + inexact = inexact.
func (*Float) Compare ¶
Compare compares this float with another number.
R7RS §6.2.6: Numeric comparisons use mathematical value regardless of exactness. Returns -1 if p < o, 0 if p == o, 1 if p > o.
func (*Float) EqualTo ¶
EqualTo returns true if both floats have the same value. Handles comparison with both Float and BigFloat types for symmetry.
func (*Float) HashCode ¶
HashCode returns a hash of the float value. Uses the canonical inexact-family hash so that Float and BigFloat produce identical hashes for equal values. NaN and Inf use bitwise hashing as a fallback since BigFloat has no Inf/NaN, making cross-type equality impossible for those values.
func (*Float) IsExact ¶
IsExact returns false since Float is always inexact.
R7RS §6.2.2: Floating-point numbers are inexact.
func (*Float) IsFinite ¶ added in v1.1.0
IsFinite returns true if this float is finite (not Inf or NaN).
R7RS §6.2.6: finite? returns #t for finite numbers.
func (*Float) IsInteger ¶ added in v1.1.0
IsInteger returns true if this float represents an integer value.
R7RS §6.2.6: integer? returns #t for inexact integers (e.g., 3.0). Uses math.Trunc to correctly handle large floats outside int64 range.
func (*Float) IsNaN ¶ added in v1.1.0
IsNaN returns true if this float is NaN.
R7RS §6.2.6: nan? returns #t for NaN values.
func (*Float) IsNegative ¶ added in v1.1.0
IsNegative returns true if this float is negative.
func (*Float) IsPositive ¶ added in v1.1.0
IsPositive returns true if this float is positive.
func (*Float) IsRational ¶ added in v1.1.0
IsRational returns true if this float is finite (not NaN or Inf).
R7RS §6.2.6: rational? returns #t for finite inexact reals.
func (*Float) Kind ¶ added in v1.5.0
func (p *Float) Kind() NumericKind
Add returns the sum of two numbers.
Kind returns the numeric kind for dispatch table indexing.
func (*Float) Multiply ¶
Multiply returns the product of two numbers.
R7RS §6.2.6: The * procedure returns the product of its arguments. R7RS §6.2.2: Exact zero dominates—(* 0 x) may return exact 0 even when x is inexact. Zero is an exact value when the result is mathematically unambiguous. This implementation follows Chez Scheme's behavior.
func (*Float) Negate ¶
Negate returns the negation of this float.
R7RS §6.2.6: The - procedure with one argument returns the additive inverse.
func (*Float) SchemeString ¶
SchemeString returns the Scheme representation of the float.
R7RS §6.2.5: +inf.0, -inf.0, and +nan.0 are the written representations for positive infinity, negative infinity, and NaN. R7RS §7.1.1: Inexact real numbers must contain a decimal point to distinguish them from exact integers.
func (*Float) Sign ¶ added in v1.1.0
Sign returns -1 if negative, 0 if zero, or 1 if positive. NaN returns 0.
func (*Float) Subtract ¶
Subtract returns the difference of two numbers.
R7RS §6.2.6: The - procedure returns the difference of its arguments. R7RS §6.2.2 Exactness: inexact - inexact = inexact, exact - inexact = inexact.
type ForEachFunc ¶
ForEachFunc is the callback signature for iterating over a Tuple.
Parameters:
- ctx: context for cancellation
- i: zero-based element index
- hasNext: true if more elements follow
- v: the current element value
Return a non-nil error to stop iteration early.
type Hashable ¶
Hashable represents a Value that can be used as a hashtable key.
R7RS §6.10: Hashtables map keys to values. Keys are compared using equal?, and the hash function must be consistent with the equality predicate: if a.EqualTo(b) then a.HashCode() == b.HashCode().
Implemented by: Integer, BigInteger, Float, BigFloat, Rational, Boolean, Character, Symbol, Byte, String.
type Hashtable ¶
type Hashtable struct {
// contains filtered or unexported fields
}
Hashtable represents a Scheme hash table mapping hashable values to values.
Separate chaining (Cormen et al., CLRS Ch. 11): collisions are resolved by storing all entries with the same hash in a linked list (here, a Go slice). O(1) amortized with a good hash function. See BIBLIOGRAPHY.md "Separate Chaining Hash Table".
Keys must implement the Hashable interface (Value + HashCode()). Uses bucket chaining with FNV-1a hashing for O(1) amortized operations and EqualTo() for key comparison within buckets.
func NewEmptyHashtable ¶
func NewEmptyHashtable() *Hashtable
NewEmptyHashtable creates a new empty hash table.
func (*Hashtable) Clear ¶
func (p *Hashtable) Clear()
Clear removes all entries from the hash table.
func (*Hashtable) Delete ¶
Delete removes the entry for key from the hash table. Returns werr.ErrInvalidArgument if the key does not implement Hashable.
func (*Hashtable) Entries ¶ added in v1.1.0
Entries iterates over all entries in the hash table, calling fn for each key-value pair. Iteration stops early if fn returns a non-nil error. This is more efficient than Keys()+Get() as it avoids intermediate allocations.
func (*Hashtable) EqualTo ¶
EqualTo returns true if both hash tables have equal contents. Uses structural equality (EqualTo) for both keys and values.
func (*Hashtable) Get ¶
Get retrieves the value associated with key. Returns the value and whether the key was found. Returns werr.ErrInvalidArgument if the key does not implement Hashable.
func (*Hashtable) HasKey ¶
HasKey returns whether the key exists in the hash table. Returns werr.ErrInvalidArgument if the key does not implement Hashable.
func (*Hashtable) SchemeString ¶
SchemeString returns the Scheme representation of this hash table.
func (*Hashtable) Set ¶
Set associates key with val in the hash table. Returns werr.ErrInvalidArgument if the key does not implement Hashable.
type InputOutputPort ¶
type InputOutputPort interface {
InputPort
OutputPort
}
InputOutputPort represents a bidirectional Scheme port.
type Integer ¶
type Integer struct {
Value int64
}
Integer represents a Scheme integer value.
R7RS §6.2.1: Integers are exact numbers in the numeric tower hierarchy:
number ⊃ complex ⊃ real ⊃ rational ⊃ integer
R7RS §6.2.2: Integer is always exact. Operations on exact numbers produce exact results when mathematically well-defined.
func NewInteger ¶
NewInteger returns an Integer value. Small integers in the range -32768 to 32767 are cached and return the same pointer for the same value.
func (*Integer) Add ¶
R7RS §6.2.2 Exactness: exact + exact = exact, exact + inexact = inexact. When adding Integer + BigInteger, result is BigInteger (exact). When adding Integer + Float/Complex, result is Float/Complex (inexact).
func (*Integer) Compare ¶
Compare compares this integer with another number.
R7RS §6.2.6: Numeric comparisons use mathematical value regardless of exactness. Returns -1 if p < o, 0 if p == o, 1 if p > o.
func (*Integer) Divide ¶
Divide returns the quotient of this integer and another number.
R7RS §6.2.6: The / procedure returns the quotient of its arguments. For exact arguments, / may return a non-integer (Rational) when the mathematical result is not an integer. Returns Integer only when the division is exact.
R7RS §6.2.2 Exactness: exact / exact = exact (Integer or Rational), exact / inexact = inexact (Float or Complex).
func (*Integer) EqualTo ¶
EqualTo returns true if both integers have the same value.
R7RS §6.2.6: The = procedure compares numerical values for equality. This implements structural equality for the Integer type specifically. Handles comparison with Integer, BigInteger, and Rational types for symmetry.
func (*Integer) HashCode ¶
HashCode returns a hash of the integer value. Uses the canonical exact-family hash so that Integer, BigInteger, and Rational produce identical hashes for equal values.
func (*Integer) IsExact ¶
IsExact returns true since Integer is always exact.
R7RS §6.2.2: Integers are always exact numbers.
func (*Integer) IsFinite ¶ added in v1.1.0
IsFinite returns true since integers are always finite.
R7RS §6.2.6: finite? returns #t for all exact numbers.
func (*Integer) IsInteger ¶ added in v1.1.0
IsInteger returns true since Integer is always an integer.
R7RS §6.2.6: integer? returns #t for exact integers.
func (*Integer) IsNaN ¶ added in v1.1.0
IsNaN returns false since integers are never NaN.
R7RS §6.2.6: nan? returns #f for exact numbers.
func (*Integer) IsNegative ¶ added in v1.1.0
IsNegative returns true if this integer is negative.
R7RS §6.2.6: negative? returns #t if the real number is negative.
func (*Integer) IsPositive ¶ added in v1.1.0
IsPositive returns true if this integer is positive.
R7RS §6.2.6: positive? returns #t if the real number is positive.
func (*Integer) IsRational ¶ added in v1.1.0
IsRational returns true since integers are a subset of rationals.
R7RS §6.2.6: rational? returns #t for all real finite numbers.
func (*Integer) Kind ¶ added in v1.5.0
func (p *Integer) Kind() NumericKind
Add returns the sum of this integer and another number.
R7RS §6.2.6: The + procedure returns the sum of its arguments. Kind returns the numeric kind for dispatch table indexing.
func (*Integer) LessThan ¶
LessThan returns true if this integer is less than another number.
R7RS §6.2.6: The < procedure returns #t if its arguments are monotonically increasing. Comparison across numeric types uses mathematical value.
func (*Integer) Multiply ¶
Multiply returns the product of this integer and another number.
R7RS §6.2.6: The * procedure returns the product of its arguments. R7RS §6.2.2 Exactness: exact * exact = exact, exact * inexact = inexact. Exception: Exact zero dominates—(* 0 x) may return exact 0 even when x is inexact. Zero is an exact value when the result is mathematically unambiguous. This implementation follows Chez Scheme's behavior.
func (*Integer) Negate ¶
Negate returns the negation of this integer.
R7RS §6.2.6: The - procedure with one argument returns the additive inverse.
func (*Integer) SchemeString ¶
SchemeString returns the Scheme representation of this integer.
func (*Integer) Subtract ¶
Subtract returns the difference of this integer and another number.
R7RS §6.2.6: The - procedure returns the difference of its arguments. R7RS §6.2.2 Exactness: exact - exact = exact, exact - inexact = inexact.
type JoinTimeoutException ¶
type JoinTimeoutException struct{}
JoinTimeoutException is raised when thread-join! times out
func (*JoinTimeoutException) Error ¶
func (p *JoinTimeoutException) Error() string
type Mutex ¶
type Mutex struct {
// contains filtered or unexported fields
}
Mutex represents a Scheme mutex (SRFI-18)
func (*Mutex) Lock ¶
Lock acquires the mutex with optional timeout and owner Returns true if acquired, false if timeout
func (*Mutex) MarkAbandoned ¶
func (p *Mutex) MarkAbandoned()
MarkAbandoned marks the mutex as abandoned (called when owner thread terminates)
func (*Mutex) SchemeString ¶
SchemeString returns the Scheme representation of the mutex.
func (*Mutex) SetSpecific ¶
SetSpecific sets the mutex's specific field
func (*Mutex) State ¶
func (p *Mutex) State() MutexState
State returns the current state of the mutex
func (*Mutex) StateValue ¶
StateValue returns the state as a Scheme value. Returns package-level singletons for symbol states so that repeated calls return the same pointer: (eq? (mutex-state m) (mutex-state m)) → #t. See the doc comment on SymbolThreadNew in thread.go for eq? vs equal? caveats. Returns: 'not-owned, 'abandoned, or the owner thread.
type MutexState ¶
type MutexState int
MutexState represents the state of a mutex
const ( MutexUnlocked MutexState = iota // Not locked MutexLockedOwned // Locked with owner MutexLockedNotOwned // Locked without owner MutexAbandoned // Owner terminated while holding lock )
MutexState constants.
func (MutexState) String ¶
func (p MutexState) String() string
type NamedTypeConstraint ¶ added in v1.12.0
type NamedTypeConstraint struct {
// contains filtered or unexported fields
}
NamedTypeConstraint represents an unresolved type name from a docstring (e.g., "point"). It is documentation-only — Check always fails because the constraint has not been resolved to a concrete type.
func NewNamedTypeConstraint ¶ added in v1.12.0
func NewNamedTypeConstraint(name string) *NamedTypeConstraint
NewNamedTypeConstraint creates a NamedTypeConstraint with the given name.
func (*NamedTypeConstraint) Check ¶ added in v1.12.0
func (p *NamedTypeConstraint) Check(v Value) (any, bool, error)
Check always fails — the constraint is unresolved and cannot validate values.
func (*NamedTypeConstraint) Description ¶ added in v1.12.0
func (p *NamedTypeConstraint) Description() string
Description returns the unresolved type name as its description.
func (*NamedTypeConstraint) Name ¶ added in v1.12.0
func (p *NamedTypeConstraint) Name() string
Name returns the unresolved type name.
type NativeError ¶
type NativeError struct {
// contains filtered or unexported fields
}
NativeError represents an R7RS error object created by (error ...). It contains a message string and a list of irritant objects that provide additional context about the error. It can also wrap a Go error.
func NewErrorObject ¶
func NewErrorObject(message string, irritants ...Value) *NativeError
NewErrorObject creates a new error object with the given message and irritants.
func NewErrorObjectWithCause ¶
func NewErrorObjectWithCause(message string, cause error, irritants ...Value) *NativeError
NewErrorObjectWithCause creates a new error object that wraps a Go error. This preserves the original error for debugging while providing R7RS-compliant exception handling. The wrapped error can be retrieved with Datum() or Unwrap().
func NewErrorObjectWithCauseAndKind ¶
func NewErrorObjectWithCauseAndKind(message string, cause error, kind NativeErrorKind, irritants ...Value) *NativeError
NewErrorObjectWithCauseAndKind creates a new error object that wraps a Go error with a specific kind. R7RS §6.11: The kind determines which error predicate (file-error?, read-error?) matches.
func NewFileError ¶
func NewFileError(message string, irritants ...Value) *NativeError
NewFileError creates a new file error object with the given message and irritants. R7RS §6.11: file-error? predicate checks for errors during file operations.
func NewNativeError ¶
func NewNativeError(msg string) *NativeError
NewNativeError creates a new native error with the given message.
func NewReadError ¶
func NewReadError(message string, irritants ...Value) *NativeError
NewReadError creates a new read error object with the given message and irritants. R7RS §6.11: read-error? predicate checks for errors during reading.
func (*NativeError) Datum ¶
func (p *NativeError) Datum() error
Datum returns the underlying Go error, if any.
func (*NativeError) EqualTo ¶
func (p *NativeError) EqualTo(v Value) bool
EqualTo returns true if this error object is equal to the given value.
func (*NativeError) Error ¶
func (p *NativeError) Error() string
Error implements the error interface.
func (*NativeError) Irritants ¶
func (p *NativeError) Irritants() Value
Irritants returns the list of irritant objects.
func (*NativeError) IsFileError ¶
func (p *NativeError) IsFileError() bool
IsFileError returns true if this is a file error.
func (*NativeError) IsReadError ¶
func (p *NativeError) IsReadError() bool
IsReadError returns true if this is a read error.
func (*NativeError) IsVoid ¶
func (p *NativeError) IsVoid() bool
IsVoid returns true if this error object is nil.
func (*NativeError) Kind ¶
func (p *NativeError) Kind() NativeErrorKind
Kind returns the error kind for R7RS error predicates.
func (*NativeError) Message ¶
func (p *NativeError) Message() *String
Message returns the error message string.
func (*NativeError) SchemeString ¶
func (p *NativeError) SchemeString() string
SchemeString returns the Scheme string representation of this error object.
func (*NativeError) Unwrap ¶
func (p *NativeError) Unwrap() error
Unwrap returns the underlying Go error for errors.Unwrap compatibility.
type NativeErrorKind ¶
type NativeErrorKind int
NativeErrorKind represents the type of an error object for R7RS error predicates.
const ( // NativeErrorKindGeneric is a generic error (default). NativeErrorKindGeneric NativeErrorKind = iota // NativeErrorKindRead is a read error (from reading data). NativeErrorKindRead // NativeErrorKindFile is a file error (from file operations). NativeErrorKindFile )
type Number ¶
type Number interface {
Value
Kind() NumericKind
Add(Number) Number
Subtract(Number) Number
Multiply(Number) Number
Divide(Number) (Number, error)
Negate() Number
Abs() Number
ToExact() (Number, error)
ToInexact() Number
IsZero() bool
IsExact() bool
IsInteger() bool // R7RS §6.2.6: is this an integer value?
IsRational() bool // R7RS §6.2.6: is this a rational value?
IsFinite() bool // R7RS §6.2.6: is this a finite number?
IsNaN() bool // R7RS §6.2.6: is this NaN?
LessThan(Number) bool
Compare(Number) int
}
Number represents a numeric value in the Scheme numeric tower.
R7RS §6.2.1: Numbers form a tower: number ⊃ complex ⊃ real ⊃ rational ⊃ integer. All numeric types implement this interface for uniform arithmetic operations.
Error signaling ¶
Arithmetic methods signal errors by panicking with a static sentinel error (e.g., werr.ErrDivisionByZero, werr.ErrNotANumber). This follows the same convention used by Go's math/big package, where (*big.Int).Div, (*big.Int).QuoRem, and (*big.Float).Quo all panic on division by zero, and mirrors Go's own runtime behavior for built-in integer division.
Divide returns (Number, error) so callers can propagate division-by-zero without panic/recover. All other arithmetic methods remain single-return because they cannot fail.
func Promote ¶ added in v1.5.0
func Promote(n Number, target NumericKind) Number
Promote converts a Number to the target NumericKind using the lossless promoter table. Panics if no promotion path exists (indicates a bug in the promotion table — all reachable paths should be populated).
func Simplify ¶
Simplify attempts to reduce a number to a simpler type without losing information.
Simplification rules: - BigComplex with zero imaginary → real part - Complex with zero imaginary → Float → possibly Integer - BigFloat that is an integer → BigInteger → possibly Integer - Float that is an integer → Integer - Rational that is an integer → BigInteger → possibly Integer - BigInteger that fits int64 → Integer
type NumericKind ¶ added in v1.5.0
type NumericKind uint8
NumericKind identifies a concrete numeric type for dispatch table indexing.
Used by the receiver-centric dispatch tables in each numeric type file to replace 7-way type switches with O(1) array lookups.
ADDING A NEW NUMERIC TYPE requires updates in these locations:
- values/numeric_kind.go — add KindXxx constant (this file)
- values/xxx.go — new type file: implement Number interface, declare [numKinds] dispatch tables, register via init() calling makeXxxDispatch helpers
- values/promotion.go — add row/column in promotionTable and promoter, update NumberToFloat64, NumberToComplex128
- values/numeric_tower.go — update Simplify, ExactnessOf
- values/numeric_dispatch_test.go — add new dispatch tables to TestAllDispatchEntriesPopulated
- registry/helpers/value_conv.go — update ToComplex128, ToFloat64
- extensions/math/prim_conversion.go — update exact->inexact, number->string, etc.
- extensions/math/prim_complex.go — update make-rectangular, make-polar, etc.
- wile-goast/goast/mapper.go — (EXTERNAL REPO) update numberToAST if the type maps to a Go literal
- ffi.go — update schemeToReflectValue (line ~300)
- internal/parser/parser_number.go — if the type can be parsed from source
- registry/helpers/equality.go — update Eqv if the type has special eqv? semantics
The dispatch tables (item 2) are tested by TestAllDispatchEntriesPopulated. The type-switch functions (items 3-4, 6) are tested by TestTypeSwitchFunctionsHandleAllTypes.
const ( KindInteger NumericKind = iota KindBigInteger KindFloat KindBigFloat KindRational KindComplex KindBigComplex )
func PromotionResultKind ¶ added in v1.5.0
func PromotionResultKind(kindA, kindB NumericKind) NumericKind
PromotionResultKind returns the result type when operands of kindA and kindB are combined in an arithmetic operation. The result is the least upper bound (LUB) in the promotion lattice — symmetric and lossless.
type Once ¶
type Once struct {
// contains filtered or unexported fields
}
Once wraps sync.Once for Scheme
func (*Once) Do ¶
Do calls the function only once Returns true if this call executed the function, false if it was already called
func (*Once) SchemeString ¶
SchemeString returns the Scheme representation of the once.
type Opaque ¶ added in v1.9.1
type Opaque interface {
OpaqueTag() string
}
Opaque marks a Value as opaque to Scheme code. Any Value type can opt in by implementing this single method. The opaque? predicate checks this interface (capability check, not type check).
type OpaqueValue ¶ added in v1.9.1
type OpaqueValue struct {
// contains filtered or unexported fields
}
OpaqueValue wraps an arbitrary Go object as a Scheme value. Construction is Go-only via NewOpaqueValue. The inner value is accessible only from Go via Unwrap.
func NewOpaqueValue ¶ added in v1.9.1
func NewOpaqueValue(tag string, val any) *OpaqueValue
NewOpaqueValue creates a new opaque value with the given tag and inner value.
func (*OpaqueValue) EqualTo ¶ added in v1.9.1
func (p *OpaqueValue) EqualTo(v Value) bool
EqualTo returns true only if both are the same object (identity equality).
func (*OpaqueValue) IsVoid ¶ added in v1.9.1
func (p *OpaqueValue) IsVoid() bool
IsVoid returns true if this opaque value is nil.
func (*OpaqueValue) OpaqueTag ¶ added in v1.9.1
func (p *OpaqueValue) OpaqueTag() string
OpaqueTag returns the tag string identifying this opaque value's kind.
func (*OpaqueValue) SchemeString ¶ added in v1.9.1
func (p *OpaqueValue) SchemeString() string
SchemeString returns the Scheme representation of this opaque value.
func (*OpaqueValue) Unwrap ¶ added in v1.9.1
func (p *OpaqueValue) Unwrap() any
Unwrap returns the inner Go value. Go-only — not exposed to Scheme.
type OutputPort ¶
OutputPort represents a Scheme output port.
type Pair ¶
type Pair [2]Value
Pair represents a Scheme cons cell.
Initial algebra (Bird & de Moor 1997, Meijer et al. 1991). Proper lists are the initial algebra of a polynomial functor.
List = μX. 1 + Value × X Constructors: nil : 1 → List = EmptyList (emptyListType, not *Pair) cons : Value × List → List = NewCons(car, cdr) Eliminator (catamorphism / fold): ForEach(f) applies f to each car, returns tail Invariant: EmptyList is a separate Go type from *Pair. This encodes the two constructors as distinct injections: (pair? '()) → #f. Constrains: IsList (must terminate — uses Floyd cycle detection), PairBlock (batch allocation optimization, does not change the algebra), all list-processing primitives (must handle both constructors). Constrained by: Tuple interface (read-only view over both constructors).
See BIBLIOGRAPHY.md "Lists as Initial Algebras".
func (*Pair) Append ¶
Append appends the given Value vs to the end of the list represented by the Pair. It panics if the Pair does not represent a proper list.
R7RS §6.4: The resulting list is always newly allocated, except that it shares structure with the last argument. This implementation copies the spine of p and sets the last cdr to vs.
func (*Pair) AsVector ¶
AsVector converts the Pair representing a proper list into a Vector. It panics if the Pair does not represent a proper list.
Note: Uses context.Background() — see Length comment for circular list caveat.
func (*Pair) EqualTo ¶
EqualTo checks if the Pair is equal to another Value o. Delegates to the cycle-aware pairEqualToDeep to handle circular lists.
func (*Pair) ForEach ¶
ForEach iterates over each element in the list represented by the Pair. The provided function fn is called for each element with the index i, a boolean hasNext indicating if there are more elements, and the value v. If fn returns an error, the iteration stops and the error is returned. If the list ends with a non-empty cdr, that cdr is returned as the second return value.
func (*Pair) IsEmptyList ¶
IsEmptyList returns false. A *Pair is never the empty list; EmptyList is a separate emptyListType value.
func (*Pair) IsList ¶
IsList checks if the Pair represents a proper list. Uses Floyd's cycle detection (tortoise-and-hare) to handle circular lists. Returns false for circular lists per R7RS §6.4. See BIBLIOGRAPHY.md "Floyd's Cycle Detection".
Implementation note: This method must use *Pair (not Tuple) for cycle detection because it requires pointer identity comparison (slow == fast). Interfaces cannot be compared by pointer identity.
func (*Pair) Length ¶
Length returns the length of the list represented by the Pair. It panics if the Pair does not represent a proper list.
Note: Uses context.Background() — no cancellation path. ForEach has no cycle detection, so a circular list will hang indefinitely. Callers must ensure the receiver is a proper list (e.g., via IsList).
func (*Pair) SchemeString ¶
SchemeString returns the Scheme representation of the Pair. Handles circular structures (from datum labels or set-cdr!/set-car!) by emitting "..." when a cycle is detected.
type PairBlock ¶ added in v1.5.0
type PairBlock []Pair
PairBlock is a contiguous slice of Pairs that can be linked into a proper list. Block allocation amortizes N heap allocations to 1 for list construction.
type Port ¶
Port represents a Scheme I/O port.
R7RS §6.13: All port types support close and open-state queries.
type Process ¶ added in v1.9.1
type Process struct {
// contains filtered or unexported fields
}
Process represents a running OS process. Wraps *exec.Cmd and its connected pipes. Accessors return the ports for stdout, stderr, and stdin.
func NewProcess ¶ added in v1.9.1
func NewProcess( command string, cmd *exec.Cmd, stdin *CharacterOutputPort, stdout *CharacterInputPort, stderr *CharacterInputPort, ) *Process
NewProcess creates a Process value. The cmd may be nil for testing. Ports may be nil if the process was not started with pipes.
func (*Process) IsVoid ¶ added in v1.9.1
IsVoid reports whether this process value is void. A nil *Process is considered void to satisfy the values.Value contract.
func (*Process) SchemeString ¶ added in v1.9.1
SchemeString returns the Scheme external representation.
func (*Process) Stderr ¶ added in v1.9.1
func (p *Process) Stderr() *CharacterInputPort
Stderr returns the input port connected to the process stderr.
func (*Process) Stdin ¶ added in v1.9.1
func (p *Process) Stdin() *CharacterOutputPort
Stdin returns the output port connected to the process stdin.
func (*Process) Stdout ¶ added in v1.9.1
func (p *Process) Stdout() *CharacterInputPort
Stdout returns the input port connected to the process stdout.
type Promise ¶
type Promise struct {
// contains filtered or unexported fields
}
Promise represents a delayed computation (R7RS lazy evaluation). A promise contains either an unevaluated thunk or a cached result.
R7RS §4.2.5: The first time a promise is forced, its body is evaluated and the result is memoized; on subsequent forces, the memoized result is returned.
func NewForcedPromise ¶
NewForcedPromise creates an already-forced promise with the given value. This is used by make-promise when given a non-promise value.
func NewPromise ¶
NewPromise creates a new unforced promise with the given thunk. The thunk should be a procedure that takes no arguments.
func (*Promise) CachedResult ¶ added in v1.5.0
CachedResult returns the memoized result of a forced promise. Only valid when IsForced returns true.
func (*Promise) Force ¶ added in v1.5.0
Force transitions the promise from unforced to forced, caching the given result and clearing the thunk. Subsequent calls to IsForced return true and CachedResult returns the cached value.
func (*Promise) IsForced ¶ added in v1.5.0
IsForced reports whether the promise has been forced. A forced promise has a cached result and no thunk.
func (*Promise) SchemeString ¶
SchemeString returns the Scheme representation of the promise.
type RWMutex ¶
type RWMutex struct {
// contains filtered or unexported fields
}
RWMutex wraps sync.RWMutex for Scheme
func (*RWMutex) SchemeString ¶
SchemeString returns the Scheme representation of the RWMutex.
type Rational ¶
type Rational struct {
// contains filtered or unexported fields
}
Rational represents a Scheme rational number (exact fraction).
func NewRational ¶
NewRational creates a new Rational from numerator and denominator. The fraction is automatically normalized (reduced to lowest terms).
func NewRationalFromBigInt ¶
NewRationalFromBigInt creates a new Rational from big.Int numerator and denominator.
func NewRationalFromRat ¶
NewRationalFromRat creates a Rational from an existing big.Rat.
func (*Rational) Add ¶
R7RS §6.2.6: The + procedure returns the sum of its arguments. R7RS §6.2.2 Exactness: exact + exact = exact, exact + inexact = inexact. Inexactness is contagious per R7RS §6.2.2.
func (*Rational) Compare ¶
Compare compares this rational with another number.
R7RS §6.2.6: Numeric comparisons use mathematical value regardless of exactness. Returns -1 if p < o, 0 if p == o, 1 if p > o.
func (*Rational) DenomInt64 ¶
DenomInt64 returns the denominator as int64 (may overflow for large values).
func (*Rational) EqualTo ¶
EqualTo returns true if the rationals have equal values. Handles comparison with Integer and BigInteger for symmetry with whole-valued rationals (e.g., 5/1 == 5).
func (*Rational) HashCode ¶
HashCode returns a hash of the rational value. Uses the canonical exact-family hash so that Integer, BigInteger, and Rational produce identical hashes for equal values.
func (*Rational) IsExact ¶
IsExact returns true since Rational is always exact.
R7RS §6.2.2: Rationals are always exact numbers.
func (*Rational) IsFinite ¶ added in v1.1.0
IsFinite returns true since exact rationals are always finite.
R7RS §6.2.6: finite? returns #t for all exact numbers.
func (*Rational) IsInteger ¶
IsInteger returns true if the rational represents an integer (denominator is 1).
func (*Rational) IsNaN ¶ added in v1.1.0
IsNaN returns false since exact rationals are never NaN.
R7RS §6.2.6: nan? returns #f for exact numbers.
func (*Rational) IsNegative ¶ added in v1.1.0
IsNegative returns true if this rational is negative.
func (*Rational) IsPositive ¶ added in v1.1.0
IsPositive returns true if this rational is positive.
func (*Rational) IsRational ¶ added in v1.1.0
IsRational returns true since Rational is always a rational number.
R7RS §6.2.6: rational? returns #t for exact rationals.
func (*Rational) Kind ¶ added in v1.5.0
func (p *Rational) Kind() NumericKind
Add returns the sum of two numbers.
Kind returns the numeric kind for dispatch table indexing.
func (*Rational) Negate ¶
Negate returns the negation of this rational.
R7RS §6.2.6: The - procedure with one argument returns the additive inverse.
func (*Rational) NumInt64 ¶
NumInt64 returns the numerator as int64 (may overflow for large values).
func (*Rational) SchemeString ¶
SchemeString returns the Scheme representation of the rational.
func (*Rational) Subtract ¶
Subtract returns the difference of two numbers.
R7RS §6.2.6: The - procedure returns the difference of its arguments. R7RS §6.2.2 Exactness: exact - exact = exact, exact - inexact = inexact.
type RealNumber ¶ added in v1.1.0
RealNumber represents a real-valued number with sign operations.
R7RS §6.2.6: The positive? and negative? predicates apply only to real numbers. Sign returns -1, 0, or 1.
type Record ¶
type Record struct {
// contains filtered or unexported fields
}
Record represents a record instance as defined by R7RS define-record-type. Each record has a type descriptor and a slice of field values.
func NewRecord ¶
func NewRecord(rt *RecordType, fields []Value) *Record
NewRecord creates a new Record with the given type and field values. The fields slice should have the same length as the record type's field count.
func (*Record) EqualTo ¶
EqualTo implements structural equality for records. Two records are equal if they have the same type and all fields are equal.
func (*Record) FieldByName ¶
FieldByName returns the value of the field with the given name. Returns nil if the field is not found.
func (*Record) RecordType ¶
func (p *Record) RecordType() *RecordType
RecordType returns the record's type descriptor.
func (*Record) SchemeString ¶
SchemeString returns the Scheme external representation of the record.
func (*Record) SetFieldByName ¶
SetFieldByName sets the value of the field with the given name. Does nothing if the field is not found.
type RecordType ¶
type RecordType struct {
// contains filtered or unexported fields
}
RecordType represents a record type descriptor as defined by R7RS define-record-type. It holds the type name, the ordered list of field names, and an optional parent type for record inheritance.
func NewDerivedRecordType ¶ added in v1.12.0
func NewDerivedRecordType(name *Symbol, parent *RecordType, fieldNames []*Symbol) *RecordType
NewDerivedRecordType creates a new RecordType that inherits from the given parent.
func NewRecordType ¶
func NewRecordType(name *Symbol, fieldNames []*Symbol) *RecordType
NewRecordType creates a new RecordType with the given name and field names. The parent defaults to nil (no inheritance).
func (*RecordType) EqualTo ¶
func (p *RecordType) EqualTo(v Value) bool
EqualTo implements identity-based equality for record types. Two record types are equal only if they are the same object.
func (*RecordType) FieldCount ¶
func (p *RecordType) FieldCount() int
FieldCount returns the number of fields in this record type.
func (*RecordType) FieldIndex ¶
func (p *RecordType) FieldIndex(name *Symbol) int
FieldIndex returns the index of the field with the given name, or -1 if not found.
func (*RecordType) FieldNames ¶
func (p *RecordType) FieldNames() []*Symbol
FieldNames returns the ordered list of field name symbols.
func (*RecordType) IsVoid ¶
func (p *RecordType) IsVoid() bool
IsVoid returns true if the record type is nil.
func (*RecordType) Name ¶
func (p *RecordType) Name() *Symbol
Name returns the record type's name symbol.
func (*RecordType) Parent ¶ added in v1.12.0
func (p *RecordType) Parent() *RecordType
Parent returns the parent record type, or nil if this is a base type.
func (*RecordType) SchemeString ¶
func (p *RecordType) SchemeString() string
SchemeString returns the Scheme external representation of the record type.
type RecordTypeConstraint ¶ added in v1.12.0
type RecordTypeConstraint struct {
// contains filtered or unexported fields
}
RecordTypeConstraint validates that a value is a Record whose RecordType matches (or inherits from) a specific record type descriptor.
func NewRecordTypeConstraint ¶ added in v1.12.0
func NewRecordTypeConstraint(rtd *RecordType) *RecordTypeConstraint
NewRecordTypeConstraint creates a RecordTypeConstraint for the given record type descriptor. Panics if rtd is nil.
func (*RecordTypeConstraint) Check ¶ added in v1.12.0
func (p *RecordTypeConstraint) Check(v Value) (any, bool, error)
Check tests whether v is a Record whose type matches (or inherits from) the target record type descriptor. Walks the parent chain for subtype matching.
func (*RecordTypeConstraint) Description ¶ added in v1.12.0
func (p *RecordTypeConstraint) Description() string
Description returns a human-readable description of the record type constraint.
func (*RecordTypeConstraint) Name ¶ added in v1.12.0
func (p *RecordTypeConstraint) Name() string
Name returns the Scheme-facing name of the record type.
type SchemeWriter ¶
type SchemeWriter struct {
// contains filtered or unexported fields
}
SchemeWriter provides cycle-aware writing of Scheme values. Two-pass datum label output (R7RS §2.4): pass 1 (findShared) traverses the value graph to identify multiply-referenced objects; pass 2 (write) emits #n= definitions on first encounter and #n# references thereafter. See BIBLIOGRAPHY.md "Two-Pass Datum Label Output".
Implementation note: Uses maps with concrete *Pair and *Vector keys (not Tuple/Indexable interfaces) because: 1. Go map keys must be comparable types - interfaces are not suitable 2. Cycle/sharing detection requires pointer identity tracking 3. Each concrete type needs separate tracking for proper label assignment
func NewSchemeWriter ¶
func NewSchemeWriter() *SchemeWriter
NewSchemeWriter creates a new SchemeWriter for cycle-aware output. Default mode is WriteModeWrite (labels only circular references).
func (*SchemeWriter) WriteString ¶
func (p *SchemeWriter) WriteString(v Value) string
WriteString writes a Scheme value to a string with cycle detection. Circular and shared structures are represented using datum labels.
type SelectCase ¶
type SelectCase struct {
Channel *Channel
Value Value // for send operations
Kind SelectCaseKind
}
type SelectCaseKind ¶ added in v1.5.0
type SelectCaseKind int
SelectCase represents a case in a channel select operation SelectCaseKind distinguishes the three valid select case types.
const ( SelectReceive SelectCaseKind = iota SelectSend SelectDefault )
type SourceLocation ¶
SourceLocation represents a position in source code.
type String ¶
type String struct {
Value string
// contains filtered or unexported fields
}
String represents a Scheme string value. R7RS §6.7: Literal strings and strings from symbol->string are immutable.
func NewMutableString ¶
NewMutableString returns a mutable String value. Use this for strings that may be mutated (e.g., via string-set! or string-fill!). R7RS §6.7: Procedures like string-copy return mutable strings.
func NewString ¶
NewString returns an immutable String value. R7RS §6.7: Literal strings and strings from symbol->string are immutable. Use NewMutableString for runtime-allocated strings that may be mutated.
func (*String) Fill ¶
Fill fills the string (or a portion of it) with the given character. Returns an error if the string is immutable. R7RS §6.7: (string-fill! string fill [start [end]])
func (*String) Get ¶ added in v1.1.0
Get returns the character at the given rune index as a Character value.
R7RS §6.7: (string-ref string k) returns character k of string.
func (*String) IsImmutable ¶ added in v1.3.0
IsImmutable returns true if the string cannot be mutated. Literal strings and strings returned by symbol->string are immutable. R7RS §6.7: It is an error to apply mutation procedures to literal strings or strings returned by symbol->string.
func (*String) Length ¶ added in v1.1.0
Length returns the length of the string in characters (runes).
R7RS §6.7: (string-length string) returns the number of characters.
func (*String) SchemeString ¶
SchemeString returns the Scheme representation of the string.
func (*String) Set ¶ added in v1.1.0
Set sets the character at the given rune index from a Character value. Returns an error if the string is immutable.
R7RS §6.7: (string-set! string k char) stores char in element k.
func (*String) SetChar ¶
SetChar sets the character at index k to the given rune. Returns an error if the string is immutable.
R7RS §6.7: (string-set! string k char) R7RS §6.7: "It is an error" to mutate literal strings or strings returned by symbol->string. This implementation signals an error when mutation is attempted on immutable strings.
type StringInputPort ¶
type StringInputPort struct {
// contains filtered or unexported fields
}
StringInputPort represents a Scheme string output port backed by a buffer.
func NewStringInputPortWithBuffer ¶
func NewStringInputPortWithBuffer(buffer *bytes.Buffer) *StringInputPort
NewStringInputPortWithBuffer creates a new string output port.
func (*StringInputPort) Close ¶
func (p *StringInputPort) Close() error
Close marks the port as closed and, if a closer was provided, closes the underlying stream. Close is idempotent.
func (*StringInputPort) Datum ¶
func (p *StringInputPort) Datum() *bytes.Buffer
Datum returns the underlying buffer.
func (*StringInputPort) EqualTo ¶
EqualTo returns true if v is a port with the same kind and datum identity. This works because Go's any equality checks both dynamic type and value, so two ports sharing a kind but using different backing types (e.g., *bufio.Writer vs *bytes.Buffer) will never compare equal.
func (*StringInputPort) Flush ¶
func (p *StringInputPort) Flush() error
func (*StringInputPort) IsClosed ¶
func (p *StringInputPort) IsClosed() bool
IsClosed returns true if the port has been closed.
func (*StringInputPort) IsVoid ¶
func (p *StringInputPort) IsVoid() bool
IsVoid returns true if the port is nil.
func (*StringInputPort) Read ¶
func (p *StringInputPort) Read(bs []byte) (int, error)
Read reads data from the port into bs.
func (*StringInputPort) ReadRune ¶
func (p *StringInputPort) ReadRune() (rune, int, error)
ReadRune reads a rune from the port.
func (*StringInputPort) SchemeString ¶
func (p *StringInputPort) SchemeString() string
SchemeString returns the Scheme external representation of the port.
func (*StringInputPort) String ¶
func (p *StringInputPort) String() string
func (*StringInputPort) UnreadRune ¶
func (p *StringInputPort) UnreadRune() error
UnreadRune unreads the last rune read from the port.
type StringOutputPort ¶
type StringOutputPort struct {
// contains filtered or unexported fields
}
StringOutputPort represents a Scheme string output port backed by a buffer.
func NewStringOutputPort ¶
func NewStringOutputPort() *StringOutputPort
NewStringOutputPort creates a new string output port.
func NewStringOutputPortWithBuffer ¶
func NewStringOutputPortWithBuffer(buffer *bytes.Buffer) *StringOutputPort
NewStringOutputPortWithBuffer creates a new string output port.
func (*StringOutputPort) Close ¶
func (p *StringOutputPort) Close() error
Close marks the port as closed and, if a closer was provided, closes the underlying stream. Close is idempotent.
func (*StringOutputPort) Datum ¶
func (p *StringOutputPort) Datum() *bytes.Buffer
Datum returns the underlying buffer.
func (*StringOutputPort) EqualTo ¶
EqualTo returns true if v is a port with the same kind and datum identity. This works because Go's any equality checks both dynamic type and value, so two ports sharing a kind but using different backing types (e.g., *bufio.Writer vs *bytes.Buffer) will never compare equal.
func (*StringOutputPort) Flush ¶
func (p *StringOutputPort) Flush() error
Flush is a no-op for StringOutputPort.
func (*StringOutputPort) IsClosed ¶
func (p *StringOutputPort) IsClosed() bool
IsClosed returns true if the port has been closed.
func (*StringOutputPort) IsVoid ¶
func (p *StringOutputPort) IsVoid() bool
IsVoid returns true if the port is nil.
func (*StringOutputPort) SchemeString ¶
func (p *StringOutputPort) SchemeString() string
SchemeString returns the Scheme external representation of the port.
func (*StringOutputPort) String ¶
func (p *StringOutputPort) String() string
func (*StringOutputPort) Write ¶
func (p *StringOutputPort) Write(bs []byte) (int, error)
Write writes data to the port.
func (*StringOutputPort) WriteRune ¶
func (p *StringOutputPort) WriteRune(rn rune) (int, error)
WriteRune writes a single rune to the port's buffer.
func (*StringOutputPort) WriteString ¶
func (p *StringOutputPort) WriteString(s string) (int, error)
WriteString writes a string to the port.
type Symbol ¶
type Symbol struct {
Key string
}
Symbol represents a Scheme symbol.
func NewTemporaryVariableName ¶
func NewTemporaryVariableName() *Symbol
NewTemporaryVariableName generates a unique symbol for use as a temporary variable. The symbol name has the format "__T_<base32-encoded-random-bytes>". Uses 128 bits of cryptographic randomness to ensure uniqueness. Thread-safe: uses crypto/rand which is safe for concurrent use. Panics if random number generation fails.
func (*Symbol) SchemeString ¶
SchemeString returns the R7RS external representation of the symbol.
R7RS §7.1.1: Identifiers that can be represented without bars are written bare. Otherwise, they are enclosed in vertical bars with only \ and | characters escaped.
type TerminatedThreadException ¶
type TerminatedThreadException struct {
Thread *Thread
}
TerminatedThreadException is raised when joining a terminated thread
func (*TerminatedThreadException) Error ¶
func (p *TerminatedThreadException) Error() string
type TextualReader ¶
TextualReader represents a textual input port capable of rune-level I/O.
R7RS §6.13.2: Textual input ports support read-char, peek-char, read-line, etc.
type TextualWriter ¶
type TextualWriter interface {
OutputPort
WriteRune(rune) (int, error)
}
TextualWriter represents a textual output port capable of rune-level I/O.
R7RS §6.13.3: Textual output ports support write-char, write-string, etc.
type Thread ¶
type Thread struct {
// RunFunc is set by the machine package to actually run the thread
// This avoids circular dependency between values and machine
RunFunc func(ctx context.Context, thunk Callable) (Value, error)
// CleanupFunc is injected by the machine package to run dynamic-wind
// after thunks (UnwindTo(0)) on thread exit. Called on both normal exit
// and forced termination.
CleanupFunc func()
// contains filtered or unexported fields
}
Thread represents a Scheme thread (SRFI-18)
func (*Thread) AbandonOwnedMutexes ¶ added in v1.1.0
func (p *Thread) AbandonOwnedMutexes()
AbandonOwnedMutexes marks all mutexes owned by this thread as abandoned. Called during thread termination to ensure waiting threads are notified.
func (*Thread) Context ¶ added in v1.5.0
Context returns the context associated with this thread. Returns nil if the thread has not been started.
func (*Thread) Done ¶
func (p *Thread) Done() <-chan struct{}
Done returns a channel that's closed when the thread terminates
func (*Thread) Join ¶
Join waits for the thread to terminate with optional timeout Returns the thread's result or an error
func (*Thread) SchemeString ¶
SchemeString returns the Scheme representation of this thread.
func (*Thread) SetSpecific ¶
SetSpecific sets the thread's specific field
func (*Thread) Start ¶
Start begins execution of the thread. The parentCtx is used as the parent for the thread's cancellable context, enabling cancellation propagation from the engine/caller while allowing independent termination via thread-terminate!.
func (*Thread) State ¶
func (p *Thread) State() ThreadState
State returns the current state of the thread
func (*Thread) StateSymbol ¶
StateSymbol returns the state as a Scheme symbol. Returns package-level singletons so that repeated calls return the same pointer: (eq? (thread-state t) (thread-state t)) → #t. See the doc comment on SymbolThreadNew for eq? vs equal? caveats.
func (*Thread) Terminate ¶
func (p *Thread) Terminate()
Terminate forcefully terminates the thread. Marks all owned mutexes as abandoned and cancels the thread's context. The deferred cleanup in the goroutine (dynamic-wind after thunks) will fire when the goroutine exits. However, AbandonOwnedMutexes is also called here directly because the goroutine may be blocked on a Go-level operation (e.g., sync.Cond.Wait) and won't exit immediately on context cancellation.
func (*Thread) TrackMutex ¶ added in v1.1.0
TrackMutex adds a mutex to this thread's ownership tracking set. Called by mutex-lock! when a mutex is acquired with this thread as owner.
func (*Thread) UntrackMutex ¶ added in v1.1.0
UntrackMutex removes a mutex from this thread's ownership tracking set. Called by mutex-unlock! when a mutex is released.
type ThreadState ¶
type ThreadState int
ThreadState represents the state of a thread
const ( ThreadNew ThreadState = iota // Created but not started ThreadRunnable // Running or ready to run ThreadBlocked // Waiting for mutex/cv/sleep ThreadTerminated // Finished execution )
ThreadState constants.
func (ThreadState) String ¶
func (p ThreadState) String() string
type Time ¶
type Time struct {
// contains filtered or unexported fields
}
Time represents a point in time (SRFI-18)
func NewTimeFromSeconds ¶
NewTimeFromSeconds creates a Time from seconds since epoch
func (*Time) DurationFromNow ¶
DurationFromNow returns the duration from now until this time.
func (*Time) SchemeString ¶
SchemeString returns the Scheme representation of the time.
type Tuple ¶
type Tuple interface {
Value
// Car returns the first element of the pair (R7RS §6.4).
Car() Value
// Cdr returns the rest of the list after the first element (R7RS §6.4).
Cdr() Value
// ForEach calls fn for each element in order. Returns the tail value
// (EmptyList for proper lists, the improper cdr otherwise).
ForEach(ctx context.Context, fn ForEachFunc) (Value, error)
// Length returns the number of elements. For improper lists, this
// counts only the proper prefix.
Length() int
// Append creates a new list with value appended (R7RS §6.4 append).
Append(value Value) Value
// AsVector converts the list to a Vector (R7RS §6.4 list->vector).
AsVector() *Vector
// IsList reports whether this is a proper list (R7RS §6.4 list?).
// Uses Floyd's cycle detection (tortoise-and-hare).
IsList() bool
// IsEmptyList reports whether this is the empty list (R7RS §6.4 null?).
IsEmptyList() bool
// IsVoid reports whether this value is void (nil receiver handling).
IsVoid() bool
}
Tuple represents the Scheme list protocol — any value that can be consumed as a sequence of car/cdr pairs.
R7RS §6.4: Lists are chains of pairs terminated by the empty list. Tuple captures the operations needed to traverse, measure, and convert list-shaped values without requiring a concrete *Pair type.
Implemented by: Pair, emptyListType (EmptyList singleton).
IsVoid is listed explicitly because Pair uses a nil-receiver convention where (*Pair)(nil) represents void, and the method must be dispatched through the interface to handle that case.
var ( // EmptyList is the singleton empty list (). // It implements Tuple but is not *Pair, enforcing (pair? '()) -> #f // at the type level per R7RS 6.4. EmptyList Tuple = emptyListType{} )
func List ¶
List constructs a proper list from the given values. Returns EmptyList if no arguments are provided. The resulting list has the values in the same order as the arguments.
Implementation note: Block-allocates all Pair cells in a single slice and links them via cdr pointers. Callers receive the Tuple interface.
func VectorToList ¶
VectorToList converts a Vector to a proper list preserving element order. Returns EmptyList for nil or void vectors.
type TypeConstraint ¶ added in v1.12.0
type TypeConstraint interface {
// Name returns the Scheme-facing type name (e.g., "integer", "point").
Name() string
// Description returns a human-readable description.
Description() string
// Check tests whether v satisfies this constraint.
// On success, returns the narrowed value and true.
// On failure, returns nil, false, and an error describing the mismatch.
Check(Value) (any, bool, error)
}
TypeConstraint describes a type expectation for documentation and validation. Built-in types are represented by ValueType constants. User-defined types (e.g., record types) implement this interface directly.
A nil TypeConstraint means "unspecified" (no type info declared). TypeAny means "explicitly accepts any value."
type UncaughtThreadException ¶
type UncaughtThreadException struct {
Reason error
}
UncaughtThreadException wraps an exception that wasn't caught in a thread
func (*UncaughtThreadException) Error ¶
func (p *UncaughtThreadException) Error() string
func (*UncaughtThreadException) Unwrap ¶
func (p *UncaughtThreadException) Unwrap() error
type Value ¶
Value is the base interface for all Scheme values.
Every runtime object in Wile implements Value. The three methods correspond to fundamental Scheme operations:
- SchemeString returns the external representation (R7RS §6.13.3 write).
- IsVoid reports whether this value represents the absence of a result (e.g., the return value of set! or display). A nil receiver must return true so that missing values are treated as void.
- EqualTo implements structural equality (R7RS §6.1 equal?).
ADDING A NEW VALUE TYPE requires at minimum:
- values/<type>.go — implement Value (SchemeString, IsVoid, EqualTo)
- values/<type>_test.go — test the three Value methods + type-specific behavior
Depending on the type's role, also update:
- registry/core/prim_predicates.go — if it needs a type predicate (e.g., box?)
- ffi.go — if it maps to/from Go types via RegisterFunc
- values/scheme_writer.go — if it has internal structure that can be shared/circular
- machine/machine_context_apply.go — if it is callable (implements Callable)
- machine/native_template.go — if it can appear as a compile-time literal
For numeric types, see the more detailed guide in values/numeric_kind.go (12 items).
var EOFObject Value = eofType{}
EOFObject is the singleton EOF value.
var Void Value = voidType{}
Void is the singleton void value.
func ChannelSelect ¶
func ChannelSelect(cases []SelectCase) (idx int, val Value, ok bool)
ChannelSelect performs a select operation on multiple channels. Returns the index of the selected case and the received value (for receive cases). If a send case targets a channel that is closed concurrently, the select returns that case's index with ok=false instead of panicking.
func ForEach ¶
ForEach iterates over a Tuple value, calling fn for each element. If the value is not a Tuple, returns the value unchanged with no error. The callback receives the element index, whether more elements follow, and the element value. Returns the tail of the tuple (EmptyList for proper lists) and any error from the callback.
func Single ¶ added in v1.5.0
Single returns the sole element of a single-element Tuple, or false if the Tuple has zero or more than one element. This avoids ForEach and its closure allocation for the common case of 1-element rest-arg lists.
func StringOrFalse ¶ added in v1.10.7
StringOrFalse returns a Scheme string if s is non-empty, or #f if empty. Follows the BoolToBoolean precedent for eliminating repeated if/else patterns.
type ValueType ¶ added in v1.10.3
type ValueType uint8
ValueType represents a Scheme type constraint for extension API contracts. Each constant maps to either a concrete Go type or an interface in the values package.
const ( TypeAny ValueType = iota // any Value TypeVoid // void singleton TypeBoolean // *Boolean TypeNumber // Number interface TypeComplex // ComplexNumber interface TypeReal // RealNumber interface TypeRational // *Rational TypeInteger // *Integer | *BigInteger TypeExactInteger // alias for TypeInteger TypeFlonum // *Float | *BigFloat TypeString // *String TypeCharacter // *Character TypeSymbol // *Symbol TypeByte // *Byte TypePair // *Pair TypeList // Tuple interface TypeVector // *Vector TypeByteVector // *ByteVector TypeHashtable // *Hashtable TypeProcedure // Callable interface TypePort // Port interface TypeInputPort // InputPort interface TypeOutputPort // OutputPort interface TypeTextualInputPort // TextualReader interface TypeTextualOutputPort // TextualWriter interface TypeBinaryInputPort // BinaryReader interface TypeBinaryOutputPort // BinaryWriter interface TypeCount // sentinel — must be last )
func (ValueType) Check ¶ added in v1.10.3
Check tests whether v satisfies this type constraint. On success, returns the narrowed value and true. On failure, returns nil, false, and an error describing the mismatch.
func (ValueType) Description ¶ added in v1.10.3
Description returns a human-readable description of the type constraint.
type Vector ¶
type Vector []Value
Vector represents an R7RS vector, a fixed-size mutable array of values. Vectors are written as #(element ...) in Scheme syntax. Unlike lists, vectors provide O(1) access to elements by index.
func NewVector ¶
NewVector creates a new Vector from the given values. Returns an empty vector if no arguments are provided.
func NewVectorWithLength ¶
NewVectorWithLength creates a new Vector of the given length, with all elements initialized to the specified fill value.
func (*Vector) AsList ¶
AsList converts the vector to a proper list (linked list of pairs). Returns void (nil Pair) if the vector is void. Returns EmptyList if the vector is empty. Otherwise returns a newly constructed list containing the vector's elements.
func (*Vector) Datum ¶
Datum returns the underlying slice of values. Returns nil if the vector is void (nil pointer).
func (*Vector) EqualTo ¶
EqualTo implements structural equality for vectors. Two vectors are equal if they have the same length and all corresponding elements are equal (using recursive EqualTo comparison). Returns false if the other value is not a Vector.
func (*Vector) IsVoid ¶
IsVoid returns true if the vector is a nil pointer. A nil vector represents the absence of a value, distinct from an empty vector.
func (*Vector) Length ¶
Length returns the number of elements in the vector. Returns 0 if the vector is void (nil pointer).
func (*Vector) SchemeString ¶
SchemeString returns the Scheme external representation of the vector. Format: #( element1 element2 ... ) with elements separated by spaces. Empty vectors are represented as #().
type WaitGroup ¶
type WaitGroup struct {
// contains filtered or unexported fields
}
WaitGroup wraps sync.WaitGroup for Scheme
func (*WaitGroup) SchemeString ¶
SchemeString returns the Scheme representation of the wait group.
type WriteMode ¶
type WriteMode int
WriteMode controls how the SchemeWriter handles shared structure.
R7RS §6.13.3 specifies three output procedures with different sharing semantics:
- write: datum labels only for circular references (WriteModeWrite)
- write-shared: datum labels for all shared references (WriteModeWriteShared)
- write-simple: no datum labels at all (handled separately via SchemeString)
Source Files
¶
- atomic.go
- big_complex.go
- big_float.go
- big_integer.go
- binary_input_port.go
- binary_output_port.go
- boolean.go
- box.go
- byte.go
- byte_vector.go
- byte_vector_buffered_output_port.go
- byte_vector_input_output_port.go
- byte_vector_input_port.go
- byte_vector_output_port.go
- channel.go
- character.go
- character_input_port.go
- character_output_port.go
- compile_time_value.go
- complex.go
- condition_variable.go
- debug.go
- doc.go
- empty_list.go
- float.go
- hash.go
- hashtable.go
- integer.go
- mutex.go
- native_error.go
- numeric_kind.go
- numeric_tower.go
- once.go
- opaque.go
- opaque_value.go
- pair.go
- pair_block.go
- port_base.go
- port_helpers.go
- process.go
- promise.go
- promotion.go
- rational.go
- record.go
- record_type.go
- rw_mutex.go
- scheme_writer.go
- string.go
- string_input_port.go
- string_output_port.go
- symbol.go
- thread.go
- time.go
- utils.go
- value_type.go
- values.go
- vector.go
- wait_group.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package valuestest provides test helpers for the values package.
|
Package valuestest provides test helpers for the values package. |