Documentation ¶
Overview ¶
Package lisp provides a lisp interpreter
Index ¶
- Constants
- func AcceptTypes(names ...string) string
- func ArgExpectError(what string, pos int) error
- func CheckArityAtLeast(l List, expected int) error
- func CheckArityEqual(l List, expected int) error
- func Parse(r io.Reader) (interface{}, error)
- type EnvFunc
- type Environment
- func (e *Environment) Branch() *Environment
- func (e *Environment) DefineSymbol(symbol string, v interface{}) error
- func (e *Environment) Eval(node interface{}) (interface{}, error)
- func (e *Environment) GetSymbol(symbol string) (interface{}, error)
- func (e *Environment) QuasiQuoteEval(node interface{}) (interface{}, error)
- func (e *Environment) SetSymbol(symbol string, v interface{}) error
- func (e *Environment) UnsetSymbol(symbol string) error
- type Func
- type Keyword
- type List
- type Symbol
- type Table
- type UndefinedSymbolError
Constants ¶
const ( TypeBool = "bool" TypeFloat = "float" TypeFunction = "function" TypeInt = "int" TypeKeyword = "keyword" TypeList = "list" TypeString = "string" TypeSymbol = "symbol" TypeTable = "table" )
Lisp type names
Variables ¶
This section is empty.
Functions ¶
func AcceptTypes ¶
AcceptTypes creates a formatted list of accepted types for humans
func ArgExpectError ¶
ArgExpectError returns an error that indicates requirements for an argument
func CheckArityAtLeast ¶
CheckArityAtLeast requires the argument list to be at least certain length
func CheckArityEqual ¶
CheckArityEqual requires the argument list to be of a certain length
Types ¶
type EnvFunc ¶
type EnvFunc interface { Name() string EnvFunc(*Environment, List) (interface{}, error) }
EnvFunc is a object that can act as a function invocation in the lisp. It receives the current Environment and unevaluated arguments. This leaves it up to the function to describe how arguments should be evaluated.
type Environment ¶
Environment is a registry of symbols for a lexical scope.
func (*Environment) Branch ¶
func (e *Environment) Branch() *Environment
Branch returns a new child context Environment.
func (*Environment) DefineSymbol ¶
func (e *Environment) DefineSymbol(symbol string, v interface{}) error
DefineSymbol defines a symbol.
func (*Environment) Eval ¶
func (e *Environment) Eval(node interface{}) (interface{}, error)
Eval evaluates expressions obtained via the Parser.
func (*Environment) GetSymbol ¶
func (e *Environment) GetSymbol(symbol string) (interface{}, error)
GetSymbol performs a symbol lookup and returns the value if its present. If the symbol cannot be found in the current Environment context, it advances to the parent to see if can be found there.
func (*Environment) QuasiQuoteEval ¶
func (e *Environment) QuasiQuoteEval(node interface{}) (interface{}, error)
QuasiQuoteEval is a special evaluation mode that is used in quasiquoting. Like `quote` it doesn't evaluate any expressions. However, unlike `quote` it can evaluation some nested expressions marked by the special `unquote` function invocation.
func (*Environment) SetSymbol ¶
func (e *Environment) SetSymbol(symbol string, v interface{}) error
SetSymbol sets the value of a symbol. Like GetSymbol, it advances to parent Environments if the symbol cannot be found in the current context. If the value has not been defined yet, it errors.
func (*Environment) UnsetSymbol ¶
func (e *Environment) UnsetSymbol(symbol string) error
UnsetSymbol removes a symbol definition. It only operates on the current context; no parent Environments will be affected.
type Func ¶
Func is a object that can act as a function invocation in the lisp. It receives fully evaluated arguments.
type Keyword ¶
type Keyword string
Keyword represents a keyword lisp type
func (Keyword) Func ¶
Func implements the Func interface. It allows Keywords to be called like functions that accept a Table as their first argument to return the associated value for that key in the Table. An optional third argument can be provided as a default value to be returned if there is no value for the key.
type List ¶
type List []interface{}
List represents a list lisp type
type Table ¶
type Table map[interface{}]interface{}
Table represents a table lisp type
type UndefinedSymbolError ¶
type UndefinedSymbolError struct {
Name string
}
UndefinedSymbolError is an error returned when a symbol name cannot be found in an Environment.
func (UndefinedSymbolError) Error ¶
func (e UndefinedSymbolError) Error() string