Documentation
¶
Overview ¶
Package extract implements the core of the Extract language.
Index ¶
- Variables
- func Equal(v1, v2 any) bool
- func EvalAll[T any](env *Env, seq iter.Seq[T]) iter.Seq[any]
- func EvalAllWithRuntime[T any](env *Env, seq iter.Seq[T]) iter.Seq2[*Env, any]
- func IsEquatable(val any) bool
- type ArgumentNumError
- type Atom
- type Call
- type Env
- func (env *Env) AddModule(name Atom) *Module
- func (env *Env) All() iter.Seq2[Ident, any]
- func (env Env) Context() context.Context
- func (env *Env) GetModule(name Atom) *Module
- func (env Env) Let(ident Ident, val any) *Env
- func (env Env) Lookup(ident Ident) (any, bool)
- func (env Env) WithContext(ctx context.Context) *Env
- type Equaler
- type EvalFunc
- type Evaluator
- type Func
- type Ident
- type List
- type Module
- type NameError
- type Pattern
- type Pinned
- type Ref
- type TypeError
- type UndefinedModuleError
Constants ¶
This section is empty.
Variables ¶
var ErrPatternMatch = errors.New("arguments did not match defined patterns")
Functions ¶
func Equal ¶
Equal returns true if one of the following is true, in order:
* v1 is an Equaler and v1.Equal(v2) * v2 is an Equaler and v2.Equal(v1) * v1 == v2
If the last step is reached and either type is not comparable, the result is false.
func EvalAll ¶
EvalAll returns an iterator that evaluates each element in seq using Eval and yields the results. It uses r as the base Env for the evaluation and updates it with the result of each elements evaluation.
func EvalAllWithRuntime ¶
EvalAllWithRuntime is like EvalAll, but also yields the Env that results from each elements evaluation.
func IsEquatable ¶
IsEquatable returns true if val is capable of being equated.
Types ¶
type ArgumentNumError ¶
ArgumentNumError is returned when a function is called with the wrong number of arguments. If the function has a specific number of arguments that it expects, Expected will be >= 0.
func (*ArgumentNumError) Error ¶
func (err *ArgumentNumError) Error() string
type Atom ¶
type Atom struct {
// contains filtered or unexported fields
}
Atom is an interned string. Atoms are comparable and are very efficient to compare, but slightly less efficient to create at runtime or to convert back to a string.
The parser will automatically create these from atom literals.
type Call ¶
type Call struct {
*List
}
Call is a function call. It calls the first element of the underlying list with the remainder of the list as arguments. If the list is empty, it just returns the list.
type Env ¶
type Env struct {
// contains filtered or unexported fields
}
Env is the language's state. It tracks global data that is necessary throughout an Extract program, such as declared modules. A runtime is necessary to properly evaluate Extract code. To do so, use the context returned by a runtime's [Context] method.
func Eval ¶
Eval evaluates a value, potentially passing arguments to it. If the value implements Evaluator, its Eval method is called. If not and arguments were provided, the value is returned as the first element of a list containing it and the arguments provided. Otherwise, the value is returned unmodified.
func Run ¶
Run runs a list like it's the body of a function. If any elements of the list return an error when evaluated, this function returns early with that error. Otherwise, it returns the result of the evaluation of the last element of the list.
func (*Env) AddModule ¶
AddModule declares a new module with the given name. If the module already exists, it returns nil.
func (*Env) All ¶
All returns an iterator that yields all bound identifiers in the order that they are looked up in.
func (*Env) GetModule ¶
GetModule finds a declared module with the given name. If no such module has been declared, it returns nil.
type Evaluator ¶
type Evaluator interface {
// Eval evaluates the value in the given [Runtime] with the given
// arguments. It returns the result of the evaluation and a new
// Runtime representing any modifications that the evaluation has
// made to it.
//
// Most implementations will simply return the Runtime unmodified.
Eval(env *Env, args *List) (*Env, any)
}
Evaluator is a value that can be evaluated, possibly with arguments, such as a function.
type Func ¶
type Func struct {
// contains filtered or unexported fields
}
func (*Func) AddVariant ¶
type Ident ¶
type Ident struct {
// contains filtered or unexported fields
}
Ident is an identifier for bound data, i.e. a declared variable/function.
type List ¶
type List struct {
// contains filtered or unexported fields
}
List is a singly-linked list. It is the core building block of the language. Both a zero-value List and a nil *List are valid lists of length 0.
func CollectList ¶
CollectList creates a new list from the elements of seq in the same order that they are yielded.
func PushAll ¶
PushAll pushes all of the elements of seq onto list and returns the new list that results. Note that the elements will be in the reversed order from that which they are yielded in.
func (*List) Head ¶
Head returns the value at the head of the list. In other words, the value of the this node in the linked list.
func (*List) Len ¶
Len returns the length of the list. Each node caches the length, so this operation is O(1) despite the linked list nature of the implementation.
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module is a basic building block of an Extract program. All declared functions must be declared inside of a module. Modules are identified by an atom and are global to a Env once they are declared.
type NameError ¶
type NameError struct {
Ident Ident
}
NameError is returned when an identifier was accessed but is not bound in the scope.
type Pinned ¶
type Pinned struct {
Ident Ident
}
Pinned is an identifier that has been pinned. This is used to signal during pattern matching that the value of an identifier should be matched against instead of simply binding the identifier to a new value.
type Ref ¶
type Ref struct {
// In the module that the identifier is being accessed inside of. It
// can be any expression but it must return an atom or an error.
In any
// Name is the identifier being accessed.
Name Ident
}
Ref is an access of an identifier namespaced with a module.
type TypeError ¶
TypeError is returned by expressions that have incorrect types in them in some way. Val is the value that is of the wrong type. If there is information about types that were expected, the Expected field will contain it.
func NewTypeError ¶
NewTypeError is a convience function that creates a new TypeError.
type UndefinedModuleError ¶
type UndefinedModuleError struct {
Name Atom
}
UndefinedModuleError is returned when an attempt is made to access a module that has not been defined.
func (*UndefinedModuleError) Error ¶
func (err *UndefinedModuleError) Error() string
Directories
¶
| Path | Synopsis |
|---|---|
|
Package literal defines types created by the parser from literals.
|
Package literal defines types created by the parser from literals. |
|
Package parser implements a parser for Extract code.
|
Package parser implements a parser for Extract code. |
|
Package scanner implements a scanner for Extract tokens.
|
Package scanner implements a scanner for Extract tokens. |