Documentation
¶
Index ¶
- Variables
- func EvalBoolean(v Value) (BooleanType, Value)
- func EvalDictionary(v Value) (*DictionaryType, Value)
- func EvalList(v Value) (*ListType, Value)
- func EvalNumber(v Value) (NumberType, Value)
- func EvalString(v Value) (StringType, Value)
- func IsInt(n NumberType) bool
- func StrictDump(v Value) (StringType, Value)
- type Arguments
- type BooleanType
- type DictionaryType
- type ErrorType
- func NewError(n, m string, xs ...interface{}) *ErrorType
- func NotBooleanError(v Value) *ErrorType
- func NotCollectionError(v Value) *ErrorType
- func NotDictionaryError(v Value) *ErrorType
- func NotEffectError(v Value) *ErrorType
- func NotFunctionError(v Value) *ErrorType
- func NotIntError(n NumberType) *ErrorType
- func NotListError(v Value) *ErrorType
- func NotNumberError(v Value) *ErrorType
- func NotOrderedError(v Value) *ErrorType
- func NotSequenceError(v Value) *ErrorType
- func NotStringError(v Value) *ErrorType
- func OutOfRangeError() *ErrorType
- func TypeError(v Value, typ string) *ErrorType
- func ValueError(m string, xs ...interface{}) *ErrorType
- type FunctionType
- type KeyValue
- type KeywordArgument
- type ListType
- type NilType
- type NumberType
- type OptionalParameter
- type PositionalArgument
- type Signature
- type StringType
- type Thunk
- type Value
Constants ¶
This section is empty.
Variables ¶
var ( // True is a true value. True = &trueStruct // False is a false value. False = &falseStruct )
var Add = newCommutativeOperator(0, func(n, m NumberType) NumberType { return n + m })
Add sums up numbers of arguments.
var Assign = NewLazyFunction( NewSignature([]string{"collection"}, "keyValuePairs", nil, ""), func(vs ...Value) (result Value) { c, err := evalCollection(vs[0]) if err != nil { return err } l, err := EvalList(vs[1]) if err != nil { return err } for !l.Empty() { k := l.First() if l, err = EvalList(l.Rest()); err != nil { return err } c, err = evalCollection(c.assign(EvalPure(k), l.First())) if err != nil { return err } if l, err = EvalList(l.Rest()); err != nil { return err } } return c })
Assign inserts an element into a sequence.
var Catch = NewLazyFunction( NewSignature([]string{"error"}, "", nil, ""), func(vs ...Value) Value { err, ok := EvalPure(vs[0]).(*ErrorType) if !ok { return Nil } return NewDictionary([]KeyValue{ {NewString("name"), NewString(err.name)}, {NewString("message"), NewString(err.message)}, }) })
Catch returns a dictionary containing a name and message of a catched error, or nil otherwise.
var Compare = NewStrictFunction( NewSignature([]string{"left", "right"}, "", nil, ""), compareAsOrdered)
Compare compares 2 values and returns -1 when x < y, 0 when x = y, and 1 when x > y.
var Delete = NewStrictFunction( NewSignature([]string{"collection", "elem"}, "", nil, ""), func(vs ...Value) Value { c, err := evalCollection(vs[0]) if err != nil { return err } return c.delete(EvalPure(vs[1])) })
Delete deletes an element corresponding with a key.
var Div = newInverseOperator(func(n, m NumberType) NumberType { return n / m })
Div divides the first argument by arguments of the second to the last one by one.
var DummyError = NewError("DummyError", "DummyMessage")
DummyError is an error used for tests.
var Dump = NewLazyFunction( NewSignature([]string{"arg"}, "", nil, ""), func(vs ...Value) Value { s, err := StrictDump(vs[0]) if err != nil { return err } return s })
Dump dumps a value into a string type value.
var (
// EmptyDictionary is a thunk of an empty dictionary.
EmptyDictionary = &emtpyDictionary
)
var (
// EmptyList is a thunk of an empty list.
EmptyList = &emptyList
)
var Equal = NewLazyFunction( NewSignature(nil, "args", nil, ""), func(vs ...Value) (v Value) { defer func() { if r := recover(); r != nil { v = r.(Value) } }() l, err := EvalList(vs[0]) if err != nil { return err } else if l.Empty() { return True } e := EvalPure(l.First()) for { l, err = EvalList(l.Rest()) if err != nil { return err } else if l.Empty() { return True } if compare(e, EvalPure(l.First())) != 0 { return False } } })
Equal checks if all arguments are equal or not.
var Error = NewLazyFunction( NewSignature([]string{"name", "messasge"}, "", nil, ""), func(vs ...Value) Value { n, err := EvalString(vs[0]) if err != nil { return err } m, err := EvalString(vs[1]) if err != nil { return err } return &ErrorType{string(n), string(m), []*debug.Info{debug.NewGoInfo(1)}} })
Error creates an error value with an error name and message.
var FloorDiv = newInverseOperator(func(n, m NumberType) NumberType { return NumberType(math.Floor(float64(n / m))) })
FloorDiv divides the first argument by arguments of the second to the last one by one.
var If = NewLazyFunction( NewSignature(nil, "args", nil, ""), func(vs ...Value) Value { v := vs[0] for { l, err := EvalList(v) if err != nil { return err } ll, err := EvalList(l.Rest()) if err != nil { return err } else if ll.Empty() { return l.First() } b, err := EvalBoolean(l.First()) if err != nil { return err } else if b { return ll.First() } v = ll.Rest() } })
If returns the second argument when the first one is true or the third one otherwise.
var Include = NewStrictFunction( NewSignature([]string{"collection", "elem"}, "", nil, ""), func(vs ...Value) Value { c, err := evalCollection(vs[0]) if err != nil { return err } return c.include(EvalPure(vs[1])) })
Include returns true if a collection includes an element, or false otherwise.
var Index = NewStrictFunction( NewSignature([]string{"collection", "key"}, "keys", nil, ""), func(vs ...Value) Value { v := vs[0] l := cons(vs[1], vs[2]) for !l.Empty() { c, err := evalCollection(v) if err != nil { return err } v = c.index(EvalPure(l.First())) if l, err = EvalList(l.Rest()); err != nil { return err } } return v })
Index extracts an element corresponding with a key.
var IsOrdered = NewLazyFunction( NewSignature([]string{"arg"}, "", nil, ""), isOrdered)
IsOrdered checks if a value is ordered or not.
var Mod = newBinaryOperator(math.Mod)
Mod calculate a remainder of a division of the first argument by the second one.
var Mul = newCommutativeOperator(1, func(n, m NumberType) NumberType { return n * m })
Mul multiplies numbers of arguments.
var Nil = NilType{}
Nil is the evil or million-dollar mistake.
var Partial = FunctionType(func(vars Arguments) Value { return NewRawFunction(func(args Arguments) Value { vars := vars v := EvalPure(vars.nextPositional()) f, ok := v.(FunctionType) if !ok { return NotFunctionError(v) } return f.call(vars.Merge(args)) }) })
Partial creates a partially-applied function with arguments.
var Pow = newBinaryOperator(math.Pow)
Pow calculates an exponentiation from a base of the first argument and an exponent of the second argument.
var Prepend = NewLazyFunction( NewSignature(nil, "elemsAndList", nil, ""), prepend)
Prepend prepends multiple elements to a list of the last argument.
var Pure = NewLazyFunction( NewSignature([]string{"arg"}, "", nil, ""), func(vs ...Value) Value { return EvalImpure(vs[0]) })
Pure extracts a result value in an effect value.
var Size = newUnaryCollectionFunction(func(c collection) Value { return c.size() })
Size returns a size of a collection.
var Sub = newInverseOperator(func(n, m NumberType) NumberType { return n - m })
Sub subtracts arguments of the second to the last from the first one as numbers.
var ToList = newUnaryCollectionFunction(func(c collection) Value { return c.toList() })
ToList converts a collection into a list of its elements.
var ToString = NewLazyFunction( NewSignature([]string{"arg"}, "", nil, ""), func(vs ...Value) Value { v := EvalPure(vs[0]) s, ok := v.(stringable) if !ok { return TypeError(v, "stringable") } return s.string() })
ToString converts some value into one of StringType.
var TypeOf = NewLazyFunction( NewSignature([]string{"arg"}, "", nil, ""), typeOf)
TypeOf returns a type name of an argument as a string.
Functions ¶
func EvalBoolean ¶
func EvalBoolean(v Value) (BooleanType, Value)
EvalBoolean evaluates a thunk which is expected to be a boolean value.
func EvalDictionary ¶
func EvalDictionary(v Value) (*DictionaryType, Value)
EvalDictionary evaluates a thunk which is expected to be a dictionary value.
func EvalNumber ¶
func EvalNumber(v Value) (NumberType, Value)
EvalNumber evaluates a thunk which is expected to be a number value.
func EvalString ¶
func EvalString(v Value) (StringType, Value)
EvalString evaluates a thunk which is expected to be a string value.
func StrictDump ¶
func StrictDump(v Value) (StringType, Value)
StrictDump is a variant of Dump which evaluates input strictly.
Types ¶
type Arguments ¶
type Arguments struct {
// contains filtered or unexported fields
}
Arguments represents a structured set of arguments passed to a predicate. It allows destructive operations to internal properties because it is guaranteed by Thunks that arguments objects are never reused as a function call creates a Thunk.
func NewArguments ¶
func NewArguments(ps []PositionalArgument, ks []KeywordArgument) Arguments
NewArguments creates a new Arguments.
func NewPositionalArguments ¶
NewPositionalArguments creates an Arguments which consists of unexpanded positional arguments.
type BooleanType ¶
type BooleanType bool
BooleanType represents a boolean values in the language.
func NewBoolean ¶
func NewBoolean(b bool) *BooleanType
NewBoolean converts a Go boolean value into BooleanType.
type DictionaryType ¶
DictionaryType represents a dictionary in the language.
type ErrorType ¶
type ErrorType struct {
// contains filtered or unexported fields
}
ErrorType represents errors in the language and traces function calls for debugging.
func NotBooleanError ¶
NotBooleanError creates an error value for an invalid value which is not a bool.
func NotCollectionError ¶
NotCollectionError creates an error value for an invalid value which is not a collection.
func NotDictionaryError ¶
NotDictionaryError creates an error value for an invalid value which is not a dictionary.
func NotEffectError ¶
NotEffectError creates an error value for a pure value which is expected to be an effect value.
func NotFunctionError ¶
NotFunctionError creates an error value for an invalid value which is not a function.
func NotIntError ¶
func NotIntError(n NumberType) *ErrorType
NotIntError creates an error value for a number value which is not an integer.
func NotListError ¶
NotListError creates an error value for an invalid value which is not a list.
func NotNumberError ¶
NotNumberError creates an error value for an invalid value which is not a number.
func NotOrderedError ¶
NotOrderedError creates an error value for an invalid value which is not ordered.
func NotSequenceError ¶
NotSequenceError creates an error value for an invalid value which is not a sequence.
func NotStringError ¶
NotStringError creates an error value for an invalid value which is not a string.
func OutOfRangeError ¶
func OutOfRangeError() *ErrorType
OutOfRangeError creates an error value for an out-of-range index to a list.
func ValueError ¶
ValueError creates an error value for some invalid value detected at runtime.
type FunctionType ¶
FunctionType represents a function.
var First FunctionType
First takes the first element in a list.
var Insert FunctionType
Insert inserts an element into a sequence.
var Merge FunctionType
Merge merges more than 2 collections.
var Rest FunctionType
Rest returns a list which has the second to last elements of a given list.
func NewLazyFunction ¶
func NewLazyFunction(s Signature, f func(...Value) Value) FunctionType
NewLazyFunction creates a function whose arguments are evaluated lazily.
func NewRawFunction ¶
func NewRawFunction(f func(Arguments) Value) FunctionType
NewRawFunction creates a function which takes arguments directly.
func NewStrictFunction ¶
func NewStrictFunction(s Signature, f func(...Value) Value) FunctionType
NewStrictFunction creates a function whose arguments are evaluated strictly.
type KeyValue ¶
type KeyValue struct {
Key, Value Value
}
KeyValue is a pair of a key and value inserted into dictionaries.
type KeywordArgument ¶
type KeywordArgument struct {
// contains filtered or unexported fields
}
KeywordArgument represents a keyword argument passed to a function.
func NewKeywordArgument ¶
func NewKeywordArgument(s string, v Value) KeywordArgument
NewKeywordArgument creates a KeywordArgument from a bound name and its value.
type ListType ¶
type ListType struct {
// contains filtered or unexported fields
}
ListType represents a list of values in the language. They can have infinite number of elements inside.
type NumberType ¶
type NumberType float64
NumberType represents a number in the language. It will perhaps be represented by DEC64 in the future release.
func NewNumber ¶
func NewNumber(n float64) *NumberType
NewNumber creates a thunk containing a number value.
type OptionalParameter ¶
type OptionalParameter struct {
// contains filtered or unexported fields
}
OptionalParameter represents an optional argument defined in a function.
func NewOptionalParameter ¶
func NewOptionalParameter(n string, v Value) OptionalParameter
NewOptionalParameter creates an optional argument.
type PositionalArgument ¶
type PositionalArgument struct {
// contains filtered or unexported fields
}
PositionalArgument represents a positional argument. It can be expanded as a list.
func NewPositionalArgument ¶
func NewPositionalArgument(v Value, expanded bool) PositionalArgument
NewPositionalArgument creates a PositionalArgument.
type Signature ¶
type Signature struct {
// contains filtered or unexported fields
}
Signature represents function signature.
func NewSignature ¶
func NewSignature(ps []string, pr string, ks []OptionalParameter, kr string) Signature
NewSignature defines a new Signature.
type StringType ¶
type StringType string
StringType represents a string in the language.
func NewString ¶
func NewString(s string) StringType
NewString creates a string in the language from one in Go.
type Thunk ¶
type Thunk struct {
// contains filtered or unexported fields
}
Thunk you all!
func AppWithInfo ¶
AppWithInfo is the same as App except that it stores debug information in the thunk.
type Value ¶
type Value interface {
// contains filtered or unexported methods
}
Value represents a value.
func NewDictionary ¶
NewDictionary creates a dictionary from keys of values and their corresponding values of thunks.
func NewEffectFunction ¶
NewEffectFunction creates a effect function which returns an effect value.
func ReturnIfEmptyList ¶
ReturnIfEmptyList returns true if a given list is empty, or false otherwise.
func StrictPrepend ¶
StrictPrepend is a strict version of the Prepend function.
Source Files
¶
- arguments.go
- boolean.go
- collection.go
- dictionary.go
- effect.go
- error.go
- function.go
- init.go
- interfaces.go
- keyword_argument.go
- keyword_parameters.go
- list.go
- nil.go
- number.go
- optional_parameter.go
- positional_argument.go
- positional_parameters.go
- sequence.go
- signature.go
- string.go
- thunk.go
- util.go
- value.go