Documentation
¶
Overview ¶
Package data provides the fundamental value types and interfaces that form the core of Ale's type system. This includes all runtime data structures (keywords, lists, vectors, objects, symbols, etc.) that implement the Value interface, along with immutable collection types and equality semantics essential for data manipulation.
Index ¶
- Constants
- Variables
- func CheckAnyArity(int) error
- func CheckFixedArity(fixed, count int) error
- func CheckMinimumArity(min, count int) error
- func CheckRangedArity(min, max, count int) error
- func DumpString(v ale.Value) string
- func Equal(l, r ale.Value) bool
- func HashBytes(b []byte) uint64
- func HashCode(v ale.Value) uint64
- func HashInt(i int) uint64
- func HashInt64(i int64) uint64
- func HashString(s string) uint64
- func MustCheckFixedArity(fixed, count int)
- func MustCheckMinimumArity(min, count int)
- func MustCheckRangedArity(min, max, count int)
- func ToQuotedString(v ale.Value) string
- func ToString(v ale.Value) string
- type Appender
- type ArityChecker
- type BigInt
- func (l *BigInt) Add(r Number) Number
- func (l *BigInt) Cmp(r Number) Comparison
- func (l *BigInt) Div(r Number) Number
- func (l *BigInt) Equal(r ale.Value) bool
- func (l *BigInt) HashCode() uint64
- func (*BigInt) IsNaN() bool
- func (*BigInt) IsNegInf() bool
- func (*BigInt) IsPosInf() bool
- func (l *BigInt) Mod(r Number) Number
- func (l *BigInt) Mul(r Number) Number
- func (l *BigInt) String() string
- func (l *BigInt) Sub(r Number) Number
- func (l *BigInt) Type() ale.Type
- type Bool
- type Bytes
- func (b Bytes) Append(v ale.Value) Sequence
- func (b Bytes) Call(args ...ale.Value) ale.Value
- func (b Bytes) Car() ale.Value
- func (b Bytes) Cdr() ale.Value
- func (b Bytes) CheckArity(argc int) error
- func (b Bytes) Count() int
- func (b Bytes) ElementAt(index int) (ale.Value, bool)
- func (b Bytes) Equal(other ale.Value) bool
- func (b Bytes) HashCode() uint64
- func (b Bytes) IndexOf(v ale.Value) (int, bool)
- func (b Bytes) IsEmpty() bool
- func (b Bytes) Reverse() Sequence
- func (b Bytes) Split() (ale.Value, Sequence, bool)
- func (b Bytes) String() string
- func (b Bytes) Type() ale.Type
- type Call
- type Comparison
- type Cons
- type Counted
- type Float
- func (l Float) Add(r Number) Number
- func (l Float) Cmp(r Number) Comparison
- func (l Float) Div(r Number) Number
- func (l Float) Equal(r ale.Value) bool
- func (l Float) HashCode() uint64
- func (l Float) IsNaN() bool
- func (l Float) IsNegInf() bool
- func (l Float) IsPosInf() bool
- func (l Float) Mod(r Number) Number
- func (l Float) Mul(r Number) Number
- func (l Float) String() string
- func (l Float) Sub(r Number) Number
- func (l Float) Type() ale.Type
- type Hashed
- type Indexed
- type Integer
- func (l Integer) Add(r Number) Number
- func (l Integer) Call(args ...ale.Value) ale.Value
- func (l Integer) CheckArity(argc int) error
- func (l Integer) Cmp(r Number) Comparison
- func (l Integer) Div(r Number) Number
- func (l Integer) Equal(r ale.Value) bool
- func (l Integer) HashCode() uint64
- func (Integer) IsNaN() bool
- func (Integer) IsNegInf() bool
- func (Integer) IsPosInf() bool
- func (l Integer) Mod(r Number) Number
- func (l Integer) Mul(r Number) Number
- func (l Integer) String() string
- func (l Integer) Sub(r Number) Number
- func (l Integer) Type() ale.Type
- type Keyword
- type List
- func (l *List) Call(args ...ale.Value) ale.Value
- func (l *List) Car() ale.Value
- func (l *List) Cdr() ale.Value
- func (l *List) CheckArity(argc int) error
- func (l *List) Count() int
- func (l *List) ElementAt(index int) (ale.Value, bool)
- func (l *List) Equal(other ale.Value) bool
- func (l *List) HashCode() uint64
- func (l *List) IsEmpty() bool
- func (l *List) Prepend(v ale.Value) Sequence
- func (l *List) Reverse() Sequence
- func (l *List) Split() (ale.Value, Sequence, bool)
- func (l *List) String() string
- func (l *List) Type() ale.Type
- type Local
- type Locals
- type Mapped
- type Mapper
- type Name
- type Named
- type Number
- type Object
- func (o *Object) Call(args ...ale.Value) ale.Value
- func (o *Object) Car() ale.Value
- func (o *Object) Cdr() ale.Value
- func (o *Object) CheckArity(argc int) error
- func (o *Object) Count() int
- func (o *Object) Equal(other ale.Value) bool
- func (o *Object) Get(k ale.Value) (ale.Value, bool)
- func (o *Object) HashCode() uint64
- func (o *Object) IsEmpty() bool
- func (o *Object) Pairs() Pairs
- func (o *Object) Put(p Pair) Sequence
- func (o *Object) Remove(k ale.Value) (ale.Value, Sequence, bool)
- func (o *Object) Split() (ale.Value, Sequence, bool)
- func (o *Object) String() string
- func (o *Object) Type() ale.Type
- type Pair
- type Pairs
- type Prepender
- type Procedure
- type Qualified
- type Ratio
- func (l *Ratio) Add(r Number) Number
- func (l *Ratio) Cmp(r Number) Comparison
- func (l *Ratio) Div(r Number) Number
- func (l *Ratio) Equal(r ale.Value) bool
- func (l *Ratio) HashCode() uint64
- func (*Ratio) IsNaN() bool
- func (*Ratio) IsNegInf() bool
- func (*Ratio) IsPosInf() bool
- func (l *Ratio) Mod(r Number) Number
- func (l *Ratio) Mul(r Number) Number
- func (l *Ratio) String() string
- func (l *Ratio) Sub(r Number) Number
- func (l *Ratio) Type() ale.Type
- type Reverser
- type Sequence
- type String
- func (s String) Append(v ale.Value) Sequence
- func (s String) Call(args ...ale.Value) ale.Value
- func (s String) Car() ale.Value
- func (s String) Cdr() ale.Value
- func (s String) CheckArity(argc int) error
- func (s String) Count() int
- func (s String) ElementAt(index int) (ale.Value, bool)
- func (s String) Equal(other ale.Value) bool
- func (s String) HashCode() uint64
- func (s String) IsEmpty() bool
- func (s String) Quote() string
- func (s String) Reverse() Sequence
- func (s String) Split() (ale.Value, Sequence, bool)
- func (s String) String() string
- func (s String) Type() ale.Type
- type Symbol
- type SymbolGenerator
- type TypePredicate
- func (t *TypePredicate) Call(args ...ale.Value) ale.Value
- func (t *TypePredicate) CheckArity(argc int) error
- func (t *TypePredicate) Equal(other ale.Value) bool
- func (t *TypePredicate) Get(key ale.Value) (ale.Value, bool)
- func (t *TypePredicate) String() string
- func (t *TypePredicate) Type() ale.Type
- type Vector
- func (v Vector) Append(e ale.Value) Sequence
- func (v Vector) Call(args ...ale.Value) ale.Value
- func (v Vector) Car() ale.Value
- func (v Vector) Cdr() ale.Value
- func (v Vector) CheckArity(argc int) error
- func (v Vector) Count() int
- func (v Vector) ElementAt(index int) (ale.Value, bool)
- func (v Vector) Equal(other ale.Value) bool
- func (v Vector) HashCode() uint64
- func (v Vector) IndexOf(val ale.Value) (int, bool)
- func (v Vector) IsEmpty() bool
- func (v Vector) Prepend(e ale.Value) Sequence
- func (v Vector) Reverse() Sequence
- func (v Vector) Split() (ale.Value, Sequence, bool)
- func (v Vector) String() string
- func (v Vector) Type() ale.Type
Constants ¶
const ( // ErrFixedArity is raised when there are too few or many arguments // provided to a fixed ArityChecker ErrFixedArity = "expected %d arguments, got %d" // ErrMinimumArity is raised when there are too few arguments provided to a // minimum ArityChecker ErrMinimumArity = "expected at least %d arguments, got %d" // ErrRangedArity is raised when there are too few or many arguments // provided to a ranged ArityChecker ErrRangedArity = "expected between %d and %d arguments, got %d" // ErrTooManyArguments is raised when there are too many arguments provided // to a maximum ArityChecker ErrTooManyArguments = "too many arity check arguments" )
const ( ErrExpectedBytes = "value is not bytes: %s" ErrIntegerOutOfRange = "integer out of byte range: %d" )
const ( CountKey = Keyword("count") InstanceKey = Keyword("instance") NameKey = Keyword("name") TypeKey = Keyword("type") )
Standard Keys
const ( // ErrExpectedInteger is raised when the value provided to ParseInteger // can't be interpreted as an integer ErrExpectedInteger = "value is not an integer: %s" // ErrDivideByZero is raised when an attempt is made to perform integer // division by zero ErrDivideByZero = "divide by zero" )
const ( // ErrExpectedFloat is raised when a call to ParseFloat can't properly // interpret its input as a floating point number ErrExpectedFloat = "value is not a float: %s" // ErrExpectedRatio is raised when a call to ParseRatio can't properly // interpret its input as a ratio ErrExpectedRatio = "value is not a ratio: %s" )
const ( // ErrExpectedString is raised when a passed value is not a String ErrExpectedString = "value is not a string: %s" // ErrInvalidIndexes is raised when an attempt to take a substring receives // invalid start and end indexes ErrInvalidIndexes = "%d and %d are not valid start/end indices" // ErrInvalidStartIndex is raised when an attempt to take a substring of a // String specifies an ending index that is lower than the starting index ErrInvalidStartIndex = "%d is an invalid start index" )
const EmptyString = String("")
EmptyString represents the... empty string
const ErrInvalidSymbol = "invalid symbol: %s"
ErrInvalidSymbol is raised when a call to ParseSymbol can't interpret its input as a proper Symbol name (local or qualified)
const ErrMapNotPaired = "map does not contain an even number of elements"
ErrMapNotPaired is raised when a call to ValuesToObject receives an odd number of args, meaning it won't be capable of zipping them into an Object
const OrMore = -1
OrMore is the constant used when you want to tell MakeArityChecker to generate a minimum arity checker
const (
SymbolGenDigits = decimal + lower + upper + "-+"
)
Variables ¶
var ( // EmptyVector represents an empty Vector EmptyVector = Vector{} )
Functions ¶
func CheckAnyArity ¶ added in v0.3.0
CheckAnyArity allows for any number of arguments
func CheckFixedArity ¶ added in v0.3.0
CheckFixedArity allows for a fixed number of arguments
func CheckMinimumArity ¶ added in v0.3.0
CheckMinimumArity allows for a minimum number of arguments
func CheckRangedArity ¶ added in v0.3.0
CheckRangedArity allows for a ranged number of arguments
func DumpString ¶
DumpString takes a Value and dumps out a bunch of info as a string
func HashCode ¶
HashCode returns a hash code for the provided Value. If the Value implements the Hashed interface, it will call us the HashCode() method. Otherwise, it will create a hash code from the stringified form of the Value
func HashString ¶
HashString returns a hash code for the provided string
func MustCheckFixedArity ¶ added in v0.3.0
func MustCheckFixedArity(fixed, count int)
MustCheckFixedArity is CheckFixedArity, but panics if the check fails
func MustCheckMinimumArity ¶ added in v0.3.0
func MustCheckMinimumArity(min, count int)
MustCheckMinimumArity is CheckMinimumArity, but panics if the check fails
func MustCheckRangedArity ¶ added in v0.3.0
func MustCheckRangedArity(min, max, count int)
MustCheckRangedArity is CheckRangedArity, but panics if the check fails
func ToQuotedString ¶
ToQuotedString converts Values to string, possibly quoting wrapped Strings
Types ¶
type Appender ¶
type Appender interface {
Sequence
// Append creates a new Sequence with the given value appended to it
Append(ale.Value) Sequence
}
Appender is a Sequence that can be appended to
type ArityChecker ¶
ArityChecker is the interface for arity checks
func MakeArityChecker ¶ added in v0.3.0
func MakeArityChecker(arity ...int) (ArityChecker, error)
MakeArityChecker produces an arity checker based on its parameters
type BigInt ¶
BigInt represents a multi-precision integer
func (*BigInt) Cmp ¶
func (l *BigInt) Cmp(r Number) Comparison
type Bool ¶
type Bool bool
Bool represents the data True or False
func (Bool) CheckArity ¶ added in v0.3.0
type Bytes ¶ added in v0.3.0
type Bytes []byte
var (
EmptyBytes Bytes
)
func (Bytes) CheckArity ¶ added in v0.3.0
type Comparison ¶
type Comparison int
Comparison represents the result of an equality comparison
const ( LessThan Comparison = iota - 1 EqualTo GreaterThan Incomparable )
Comparison results
type Cons ¶
type Cons struct {
// contains filtered or unexported fields
}
Cons cells are the standard implementation of a Pair. Unlike other Pairs (ex: List, Vector), it is not treated as a Sequence
type Counted ¶
type Counted interface {
Sequence
// Count returns the number of elements in this Sequence
Count() int
}
Counted is a Sequence that returns a count of its items
type Float ¶
type Float float64
Float represents a 64-bit floating point number
func (Float) Cmp ¶
func (l Float) Cmp(r Number) Comparison
type Hashed ¶
type Hashed interface {
ale.Value
// HashCode returns a hash code for this Value. Hash codes are used for
// efficient storage and retrieval in mapped data structures like Object
HashCode() uint64
}
Hashed can return a hash code for the value
type Indexed ¶
type Indexed interface {
Counted
// ElementAt returns the element at the specified index
ElementAt(int) (ale.Value, bool)
}
Indexed is a Sequence that has indexed elements
type Integer ¶
type Integer int64
Integer represents a 64-bit integer
func (Integer) CheckArity ¶ added in v0.3.0
func (Integer) Cmp ¶
func (l Integer) Cmp(r Number) Comparison
type Keyword ¶
type Keyword string
Keyword is a Value that represents a name that resolves to itself
func (Keyword) CheckArity ¶
type List ¶
type List struct {
// contains filtered or unexported fields
}
A List represents a singly linked List
var ( // Null represents the absence of a Value (the empty List) Null *List )
func (*List) CheckArity ¶
type Mapped ¶
type Mapped interface {
ale.Value
// Get returns the value associated with the given key
Get(ale.Value) (ale.Value, bool)
}
Mapped is the interface for Values that have accessible properties
func DumpMapped ¶
DumpMapped takes a Value and dumps out a bunch of info as a Mapped
type Mapper ¶
type Mapper interface {
Sequence
Mapped
// Put returns a new Sequence with the Pair associated in the Mapper
Put(Pair) Sequence
// Remove returns a new Sequence with the Value removed from the Mapper
Remove(ale.Value) (ale.Value, Sequence, bool)
}
Mapper is a Sequence that provides a mutable Mapped interface
type Number ¶
type Number interface {
ale.Typed
// Cmp compares this Number to another Number
Cmp(Number) Comparison
// Add adds this Number to another Number
Add(Number) Number
// Sub subtracts another Number from this Number
Sub(Number) Number
// Mul multiplies this Number by another Number
Mul(Number) Number
// Div divides this Number by another Number
Div(Number) Number
// Mod calculates the remainder of dividing this Number by another Number
Mod(Number) Number
// IsNaN returns whether this Number is not a number (NaN)
IsNaN() bool
// IsPosInf returns whether this Number is positive infinity
IsPosInf() bool
// IsNegInf returns whether this Number is negative infinity
IsNegInf() bool
}
Number describes a numeric value of some kind
func ParseFloat ¶
ParseFloat attempts to parse a string representing a float
func ParseInteger ¶
ParseInteger attempts to parse a string representing an integer
func ParseRatio ¶
ParseRatio attempts to parse a string representing a ratio
type Object ¶
type Object struct {
// contains filtered or unexported fields
}
Object maps a set of Values, known as keys, to another set of Values
var ( // EmptyObject represents an empty Object EmptyObject *Object )
func NewObject ¶
NewObject instantiates a new Object instance. Based on Phil Bagwell's Hashed Array Mapped Trie data structure. More information on HAMT's can be found at http://lampwww.epfl.ch/papers/idealhashtrees.pdf
func ValuesToObject ¶
ValuesToObject interprets a set of Values as an Object
func (*Object) CheckArity ¶
type Pair ¶
type Pair interface {
ale.Typed
// Car returns the first element of the Pair
Car() ale.Value
// Cdr returns the second element of the Pair
Cdr() ale.Value
}
Pair represents the interface for a binary structure, such as a Cons
type Prepender ¶
type Prepender interface {
Sequence
// Prepend creates a new Sequence with the given value prepended to it
Prepend(ale.Value) Sequence
}
Prepender is a Sequence that can be prepended to
type Procedure ¶
type Procedure interface {
ale.Typed
// Call invokes this Procedure with the provided arguments
Call(...ale.Value) ale.Value
// CheckArity performs a compile-time arity check
CheckArity(int) error
}
Procedure is any Value that provides a calling interface
func MakeProcedure ¶
MakeProcedure constructs a Procedure from a func that matches the standard calling signature
type Qualified ¶
type Qualified interface {
Symbol
// Domain returns the domain part of the qualified symbol
Domain() Local
}
Qualified represents a domain-qualified symbol
type Ratio ¶
Ratio represents a number having a numerator and denominator
func (*Ratio) Cmp ¶
func (l *Ratio) Cmp(r Number) Comparison
type Reverser ¶
type Reverser interface {
Sequence
// Reverse creates a new Sequence with the elements in reverse order
Reverse() Sequence
}
Reverser is a Sequence that can be reversed
type Sequence ¶
type Sequence interface {
Pair
// Split returns the split form (First and Rest) of the Sequence
Split() (ale.Value, Sequence, bool)
// IsEmpty returns whether this sequence is empty
IsEmpty() bool
}
Sequence is a series of Values that can be iterated over
type String ¶
type String string
String is the Sequence-compatible representation of string data
func (String) CheckArity ¶
type Symbol ¶
Symbol is an identifier that can be resolved
func MustParseSymbol ¶
MustParseSymbol parses a qualified Local and produces a Symbol or explodes
func NewGeneratedSymbol ¶
NewGeneratedSymbol creates a generated Symbol
func NewQualifiedSymbol ¶
NewQualifiedSymbol returns a Qualified Symbol for a specific domain
func ParseSymbol ¶
ParseSymbol parses a qualified Local and produces a Symbol
type SymbolGenerator ¶
SymbolGenerator produces instance-unique local symbols
func NewSymbolGenerator ¶
func NewSymbolGenerator() *SymbolGenerator
NewSymbolGenerator creates a new symbol generator. In general, it is safe to use the global generator because it only maintains an incrementer
func (*SymbolGenerator) Local ¶
func (g *SymbolGenerator) Local(name Local) Local
Local returns a newly generated local symbol
func (*SymbolGenerator) Prefix ¶
func (g *SymbolGenerator) Prefix() string
type TypePredicate ¶
type TypePredicate struct {
// contains filtered or unexported fields
}
func MakeTypePredicate ¶
func MakeTypePredicate(t ale.Type) *TypePredicate
MakeTypePredicate returns a TypePredicate for the given Type
func TypePredicateOf ¶
func TypePredicateOf(f ale.Value, r ...ale.Value) *TypePredicate
TypePredicateOf returns a TypePredicate for the Types of the given Values. If more than one Value is provided, the Union of their Types is returned
func (*TypePredicate) CheckArity ¶
func (t *TypePredicate) CheckArity(argc int) error
func (*TypePredicate) String ¶ added in v0.3.0
func (t *TypePredicate) String() string
func (*TypePredicate) Type ¶
func (t *TypePredicate) Type() ale.Type