Documentation
¶
Overview ¶
Package sx provides the basic objects to work with symbolic expressions.
Index ¶
- Constants
- Variables
- func IsFalse(obj Object) bool
- func IsList(obj Object) bool
- func IsNil(obj Object) bool
- func IsTrue(obj Object) bool
- func IsUndefined(obj Object) bool
- func NumCmp(x, y Number) int
- func Print(w io.Writer, obj Object) (int, error)
- type ErrImproper
- type Int64
- type ListBuilder
- type Number
- type Object
- type Pair
- func (pair *Pair) AppendBang(obj Object) *Pair
- func (pair *Pair) AsVector() Vector
- func (pair *Pair) Assoc(obj Object) *Pair
- func (pair *Pair) Car() Object
- func (pair *Pair) Cdr() Object
- func (pair *Pair) Cons(car Object) *Pair
- func (pair *Pair) Copy() *Pair
- func (pair *Pair) ExtendBang(obj *Pair) *Pair
- func (pair *Pair) GoString() string
- func (pair *Pair) Head() *Pair
- func (pair *Pair) IsAtom() bool
- func (pair *Pair) IsEqual(other Object) bool
- func (pair *Pair) IsNil() bool
- func (pair *Pair) Iterator() SequenceIterator
- func (pair *Pair) Last() (Object, error)
- func (pair *Pair) LastPair() *Pair
- func (pair *Pair) Length() int
- func (pair *Pair) LengthEqual(n int) bool
- func (pair *Pair) LengthGreater(n int) bool
- func (pair *Pair) LengthLess(n int) bool
- func (pair *Pair) MakeList() *Pair
- func (pair *Pair) Nth(n int) (Object, error)
- func (pair *Pair) Print(w io.Writer) (int, error)
- func (pair *Pair) RemoveAssoc(obj Object) *Pair
- func (pair *Pair) Reverse() (*Pair, error)
- func (pair *Pair) SetCar(obj Object)
- func (pair *Pair) SetCdr(obj Object)
- func (pair *Pair) String() string
- func (pair *Pair) Tail() *Pair
- type Printable
- type Sequence
- type SequenceIterator
- type String
- type Symbol
- type Undefined
- type Vector
- func (v Vector) GoString() string
- func (v Vector) IsAtom() bool
- func (v Vector) IsEqual(other Object) bool
- func (v Vector) IsNil() bool
- func (v Vector) Iterator() SequenceIterator
- func (v Vector) Length() int
- func (v Vector) LengthEqual(n int) bool
- func (v Vector) LengthGreater(n int) bool
- func (v Vector) LengthLess(n int) bool
- func (v Vector) MakeList() *Pair
- func (v Vector) Nth(n int) (Object, error)
- func (v Vector) Print(w io.Writer) (int, error)
- func (v Vector) String() string
Constants ¶
const VectorName = "vector"
VectorName is the name of the (vector ...) builtin
Variables ¶
var ( SymbolQuote = MakeSymbol("quote") SymbolQuasiquote = MakeSymbol("quasiquote") SymbolUnquote = MakeSymbol("unquote") SymbolUnquoteSplicing = MakeSymbol("unquote-splicing") )
Names of quotation symbols.
Used in packages sxbuiltins, sxreader.
ErrZeroNotAllowed is signalled with an argument must not be zero, e.g. for division.
var SymbolList = MakeSymbol("list")
SymbolList is the symbol of the (list ...) function.
var T = MakeSymbol("T")
T is the default true object.
Functions ¶
func IsList ¶
IsList returns true, if the object is a list, not just a pair. A list must have a nil value at the last cdr.
func IsTrue ¶
IsTrue returns true, if object is a true value.
Everything except a nil object and the empty string, is a true value.
func IsUndefined ¶
IsUndefined returns true iff the object is a undefined value
func NumCmp ¶
NumCmp compares the two number and returns -1 if x < y, 0 if x = y, and 1 if x > y.
Types ¶
type ErrImproper ¶
type ErrImproper struct{ Pair *Pair }
ErrImproper is signalled if an improper list is found where it is not appropriate.
func (ErrImproper) Error ¶
func (err ErrImproper) Error() string
Error returns a textual representation for this error.
type Int64 ¶
type Int64 int64
Int64 is a number that store 64 bit integer values.
func (Int64) GoString ¶
GoString returns the Go string representation.
type ListBuilder ¶
type ListBuilder struct {
// contains filtered or unexported fields
}
ListBuilder is a helper to build a list sequentially from start to end.
func (*ListBuilder) ExtendBang ¶
func (lb *ListBuilder) ExtendBang(lst *Pair)
ExtendBang the list by the given list, reusing the given list
func (*ListBuilder) IsEmpty ¶
func (lb *ListBuilder) IsEmpty() bool
IsEmpty returns true, if no element was added.
func (*ListBuilder) List ¶
func (lb *ListBuilder) List() *Pair
List the result, resetting the builder.
type Number ¶
Number value store numbers.
func GetNumber ¶
GetNumber returns the object as a number, if possible.
func NumDiv ¶
NumDiv divides the first by the second number.
func NumMod ¶
NumMod divides the first by the second number.
type Object ¶
type Object interface {
fmt.Stringer
fmt.GoStringer
// IsNil checks if the concrete object is nil.
IsNil() bool
// IsAtom returns true iff the object is an object that is not further decomposable.
IsAtom() bool
// IsEqual compare two objects for deep equality.
IsEqual(Object) bool
}
Object is the generic value all s-expressions must fulfill.
type Pair ¶
type Pair struct {
// contains filtered or unexported fields
}
Pair is a node containing a value for the element and a pointer to the tail. In other lisps it is often called "cell", "cons", "cons-cell", or "list".
func MakeList ¶
MakeList creates a new list with the given objects.
func (*Pair) AppendBang ¶
AppendBang updates the given pair by setting a new pair with the given object and nil as its new second object.
func (*Pair) AsVector ¶
AsVector returns a proper list as a vector
func (*Pair) Assoc ¶
Assoc returns the first pair of a list where the car IsEqual to the given object.
func (*Pair) Cons ¶
Cons prepends a value in front of a given listreturning the new list.
func (*Pair) ExtendBang ¶
ExtendBang updates the given pair by extending it with the second pair list after its end. Returns the last list node of the newly formed list beginning with `lst`, which is also the last list node of the list starting with `val`.
func (*Pair) GoString ¶
GoString returns the go string representation.
func (*Pair) Head ¶
Head returns the first object as a pair, if possible. Otherwise it returns nil.
func (*Pair) Iterator ¶
func (pair *Pair) Iterator() SequenceIterator
func (*Pair) Last ¶
Last returns the last element of a non-empty list.
func (*Pair) LastPair ¶
LastPair returns the last pair of the given pair list, or nil.
func (*Pair) Print ¶
Print write the string representation to the given Writer.
func (*Pair) RemoveAssoc ¶
RemoveAssoc deletes all pairs from the association list, where the car IsEqual to the given object. A new list is created.
func (*Pair) Reverse ¶
Reverse returns a reversed pair list.
func (*Pair) SetCar ¶
SetCar sets the car of the pair to the given object.
func (*Pair) SetCdr ¶
SetCdr sets the cdr of the pair to the given object.
type Printable ¶
type Printable interface {
// Print emits the string representation on the given Writer
Print(io.Writer) (int, error)
}
Printable is a object that has is specific representation, which is different to String().
type Sequence ¶
type Sequence interface {
Object
// Length returns the length of the sequence.
Length() int
// LengthLess reports whether the length of the sequence is less than
// the given number.
LengthLess(n int) bool
// LengthGreater reports whether the length of the sequence is greater than
// the given number.
LengthGreater(n int) bool
// LengthEqual reports whether the length of the sequence is equal to the
// given number.
LengthEqual(n int) bool
// Nth returns the n-th element of a sequence.
Nth(n int) (Object, error)
// MakeList returns the sequence as a pair list. If sequence is already a
// pair list, it is returned without copying it.
MakeList() *Pair
// Iterator return an SequenceIterator to iterate over all elements of
// the sequence in natural order.
Iterator() SequenceIterator
}
Sequence is an Object that has a finite, ordered set of elements.
type SequenceIterator ¶
type SequenceIterator interface {
// HasElement returns true if the iterator is able to return an element.
HasElement() bool
// Element returns the current element, or Undefined{} if there is no such element.
Element() Object
// Advance moves to the next element and return true if there is one.
Advance() bool
}
SequenceIterator allows to iterate over all elements of a Sequence.
type String ¶
type String string
String represents a string object.
func GetString ¶
GetString returns the object as a string, if possible
func (String) GoString ¶
GoString returns the go string representation.
func (String) IsEqual ¶
IsEqual compares two objects for equivalence.
func (String) Print ¶
Print write the string representation to the given Writer.
type Symbol ¶
type Symbol struct {
// contains filtered or unexported fields
}
Symbol represent a symbol value.
func GetSymbol ¶
GetSymbol returns the object as a symbol if possible.
func (*Symbol) GetValue ¶
GetValue return the string value of the symbol.
func (*Symbol) GoString ¶
GoString returns the go string representation.
func (*Symbol) IsNil ¶
IsNil may return true if a symbol pointer is nil.
func (*Symbol) Print ¶
Print write the string representation to the given Writer.
Source Files
¶
- boolean.go
- const.go
- list.go
- number.go
- sequence.go
- string.go
- sx.go
- symbol.go
- undef.go
- vector.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package sxbuiltins contains functions that help to build builtin functions.
|
Package sxbuiltins contains functions that help to build builtin functions. |
|
Package sxeval allows to evaluate s-expressions.
|
Package sxeval allows to evaluate s-expressions. |
|
Package sxhtml represents HTML as s-expressions.
|
Package sxhtml represents HTML as s-expressions. |