Documentation ¶
Index ¶
- Constants
- func GoError(v *LVal) error
- func GoFloat64(v *LVal) (float64, bool)
- func GoInt(v *LVal) (int, bool)
- func GoMap(v *LVal) (map[interface{}]interface{}, bool)
- func GoSlice(v *LVal) ([]interface{}, bool)
- func GoString(v *LVal) (string, bool)
- func GoValue(v *LVal) interface{}
- func Not(v *LVal) bool
- func RegisterDefaultBuiltin(name string, formals *LVal, fn LBuiltin)
- func RegisterDefaultMacro(name string, formals *LVal, fn LBuiltin)
- func RegisterDefaultSpecialOp(name string, formals *LVal, fn LBuiltin)
- func SymbolName(v *LVal) (string, bool)
- func True(v *LVal) bool
- type CallFrame
- type CallStack
- func (s *CallStack) CheckHeight() error
- func (s *CallStack) Copy() *CallStack
- func (s *CallStack) DebugPrint(w io.Writer) (int, error)
- func (s *CallStack) Pop() CallFrame
- func (s *CallStack) PushFID(src *token.Location, fid string, pkg string, name string) error
- func (s *CallStack) TerminalFID(fid string) int
- func (s *CallStack) Top() *CallFrame
- type Config
- type ErrorVal
- type LBuiltin
- type LBuiltinDef
- type LEnv
- func (env *LEnv) AddBuiltins(external bool, funs ...LBuiltinDef)
- func (env *LEnv) AddMacros(external bool, macs ...LBuiltinDef)
- func (env *LEnv) AddSpecialOps(external bool, ops ...LBuiltinDef)
- func (env *LEnv) Copy() *LEnv
- func (env *LEnv) DefinePackage(name *LVal) *LVal
- func (env *LEnv) Error(msg ...interface{}) *LVal
- func (env *LEnv) ErrorAssociate(lerr *LVal)
- func (env *LEnv) ErrorCondition(condition string, v ...interface{}) *LVal
- func (env *LEnv) ErrorConditionf(condition string, format string, v ...interface{}) *LVal
- func (env *LEnv) Errorf(format string, v ...interface{}) *LVal
- func (env *LEnv) Eval(v *LVal) *LVal
- func (env *LEnv) EvalSExpr(s *LVal) *LVal
- func (env *LEnv) FunCall(fun, args *LVal) *LVal
- func (env *LEnv) GenSym() *LVal
- func (env *LEnv) Get(k *LVal) *LVal
- func (env *LEnv) GetFun(fun *LVal) *LVal
- func (env *LEnv) GetFunName(f *LVal) string
- func (env *LEnv) GetGlobal(k *LVal) *LVal
- func (env *LEnv) InPackage(name *LVal) *LVal
- func (env *LEnv) Lambda(formals *LVal, body []*LVal) *LVal
- func (env *LEnv) Load(name string, r io.Reader) *LVal
- func (env *LEnv) LoadFile(loc string) *LVal
- func (env *LEnv) LoadLocation(name string, loc string, r io.Reader) *LVal
- func (env *LEnv) LoadString(name, exprs string) *LVal
- func (env *LEnv) MacroCall(fun, args *LVal) *LVal
- func (env *LEnv) Put(k, v *LVal) *LVal
- func (env *LEnv) PutGlobal(k, v *LVal) *LVal
- func (env *LEnv) SpecialOpCall(fun, args *LVal) *LVal
- func (env *LEnv) Terminal(expr *LVal) *LVal
- func (env *LEnv) Update(k, v *LVal) *LVal
- func (env *LEnv) UsePackage(name *LVal) *LVal
- type LFunData
- type LFunType
- type LType
- type LVal
- func Array(dims *LVal, cells []*LVal) *LVal
- func Bool(b bool) *LVal
- func Bytes(b []byte) *LVal
- func Error(err error) *LVal
- func ErrorCondition(condition string, err error) *LVal
- func ErrorConditionf(condition string, format string, v ...interface{}) *LVal
- func Errorf(format string, v ...interface{}) *LVal
- func Float(x float64) *LVal
- func Formals(argSymbols ...string) *LVal
- func Fun(fid string, formals *LVal, fn LBuiltin) *LVal
- func InitializeUserEnv(env *LEnv, config ...Config) *LVal
- func Int(x int) *LVal
- func Macro(fid string, formals *LVal, fn LBuiltin) *LVal
- func Native(v interface{}) *LVal
- func Nil() *LVal
- func QExpr(cells []*LVal) *LVal
- func QSymbol(s string) *LVal
- func Quote(v *LVal) *LVal
- func SExpr(cells []*LVal) *LVal
- func SortedMap() *LVal
- func SpecialOp(fid string, formals *LVal, fn LBuiltin) *LVal
- func Splice(v *LVal) *LVal
- func String(str string) *LVal
- func Symbol(s string) *LVal
- func Value(v interface{}) *LVal
- func (v *LVal) ArrayDims() *LVal
- func (v *LVal) ArrayIndex(index ...*LVal) *LVal
- func (v *LVal) Builtin() LBuiltin
- func (v *LVal) Bytes() []byte
- func (v *LVal) CallStack() *CallStack
- func (v *LVal) Copy() *LVal
- func (v *LVal) Env() *LEnv
- func (v *LVal) Equal(other *LVal) *LVal
- func (v *LVal) EqualNum(other *LVal) *LVal
- func (v *LVal) FID() string
- func (v *LVal) FunData() *LFunData
- func (v *LVal) IsMacro() bool
- func (v *LVal) IsNil() bool
- func (v *LVal) IsNumeric() bool
- func (v *LVal) IsSpecialFun() bool
- func (v *LVal) IsSpecialOp() bool
- func (v *LVal) Len() int
- func (v *LVal) Map() map[interface{}]*LVal
- func (v *LVal) MapGet(k interface{}) *LVal
- func (v *LVal) MapKeys() *LVal
- func (v *LVal) MapSet(k interface{}, val *LVal) *LVal
- func (v *LVal) Package() string
- func (v *LVal) SetCallStack(stack *CallStack)
- func (v *LVal) String() string
- type Loader
- type LocationReader
- type LogicalStackOverflowError
- type Package
- type PackageRegistry
- type PhysicalStackOverflowError
- type Reader
- type RelativeFileSystemLibrary
- type Runtime
- type SourceContext
- type SourceLibrary
Constants ¶
const AnonArgSymbolPrefix = "%"
AnonArgSymbolPrefix is used to indicate unnamed arguments in the anonymous function shorthand “(expr ...)”.
const DefaultLangPackage = "lisp"
DefaultLangPackage is the name of default language package
const DefaultUserPackage = "user"
DefaultUserPackage is the name of the entry point package for interpreting user code.
const FalseSymbol = "false"
FalseSymbol is the language's defacto false boolean value, though nil is also considered false by functions and operators expecting a boolean.
const KeyArgSymbol = "&key"
KeyArgSymbol is the symbol used to indicate keyword arguments to a function. Keyword arguments are declared following optional arguments. Keyword arguments may be supplied in any order and must specify the symbol they wish should be bound to by preceding the argument value with a keyward symbol.
const MetaArgPrefix = "&"
MetadaArgPrefix is a disallowed prefix for formal argument symbols. Any symbol beginning with MetaArgPrefix in a formal argument list will be treated with special meaning an unrecognized symbols will cause a runtime error to occur.
const OptArgSymbol = "&optional"
OptArgSymbol is the symbol used to indicate optional arguments to a function. Optional arguments are bound to given arguments if there are arguments left over following the binding of required arguments, otherwise they are bound to nil.
const TrueSymbol = "true"
TrueSymbol is the language's defacto true boolean value, though anything other than nil and 'false are considered true by functions and operators expecting a boolean.
const VarArgSymbol = "&rest"
VarArgSymbol is the symbol that indicates a variadic function argument in a function's list of formal arguments. Functions may have at most one variadic argument. Variadic arguments must be defined following optional arguments and are bound after all optional arguments are bound.
Currently, it is an error to declare a function which has both variadic and keyword arguments. While this may change it will always be discouraged due to the difficulty handling such mixtures of argument types. It would be better to define separate functions, one with keyward args and the other with variadic args.
Variables ¶
This section is empty.
Functions ¶
func GoFloat64 ¶
GoFloat64 converts the numeric value that v represents to a float64 and returns it with the value true. If v does not represent a number GoFloat64 returns a false second argument
func GoInt ¶
GoInt converts the numeric value that v represents to and int and returns it with the value true. If v does not represent a number GoInt returns a false second argument
func GoMap ¶
GoMap converts an LSortMap to its Go equivalent and returns it with a true second argument. If v does not represent a map GoMap returns a false second argument
func GoSlice ¶
GoSlice returns the string that v represents and the value true. If v does not represent a string GoSlice returns a false second argument
func GoString ¶
GoString returns the string that v represents and the value true. If v does not represent a string GoString returns a false second argument
func GoValue ¶
func GoValue(v *LVal) interface{}
GoValue converts v to its natural representation in Go. Quotes are ignored and all lists are turned into slices. Symbols are converted to strings. The value Nil() is converted to nil. Functions are returned as is.
NOTE: These semantics may change. It's unclear what the exact need is in corner cases.
func RegisterDefaultBuiltin ¶
RegisterDefaultBuiltin adds the given function to the list returned by DefaultBuiltins.
func RegisterDefaultMacro ¶
RegisterDefaultMacro adds the given function to the list returned by DefaultMacros.
func RegisterDefaultSpecialOp ¶
RegisterDefaultSpecialOp adds the given function to the list returned by DefaultSpecialOps.
func SymbolName ¶
SymbolName returns the name of the symbol that v represents and the value true. If v does not represent a symbol SymbolName returns a false second argument
Types ¶
type CallFrame ¶
type CallFrame struct { Source *token.Location FID string Package string Name string HeightLogical int Terminal bool TROBlock bool // Stop tail-recursion optimization from collapsing this frame }
CallFrame is one frame in the CallStack
func (*CallFrame) QualifiedFunName ¶
QualifiedFunName returns the qualified name for the function on the top of the stack. If ignore is non-empty QualifiedFunName returns unqualified names for functions in the given packages.
type CallStack ¶
CallStack is a function call stack.
func (*CallStack) CheckHeight ¶
func (*CallStack) Copy ¶
Copy creates a copy of the current stack so that it can be attach to a runtime error.
func (*CallStack) DebugPrint ¶
DebugPrint prints s
func (*CallStack) Pop ¶
Pop removes the top CallFrame from the stack and returns it. If the stack is empty Pop returns nil.
func (*CallStack) TerminalFID ¶
TerminalFID determines if a chain of terminal stack frames that ends with fid (i.e. fid is a candidate for tail-recursion optimization) and returns the number of frames in the shortest such chain. If no such chain of terminal frames can be found then 0 is returned.
If a stack frame with TROBlock is found then the search for a terminal chain is prematurely terminated as a failure.
NOTE: If tail-recursion optimization is working then the chain of calls found by TerminalFID is unique.
type Config ¶
Config is a function that configures a root environment or its runtime.
func WithLoader ¶
WithLoader returns a Config that executes fn and ensures that the environment's working package is reset following execution of fn. Despite fn having the same signature as a Config WithLoader allows a Loader to function more like the LEnv methods LoadFile, LoadString, etc.
func WithMaximumLogicalStackHeight ¶
WithMaximumLogicalStackHeight returns a Config that will prevent an execution environment from allowing the logical stack height to exceed n. The logical height of the stack is the stack's physical height plus the number of stack frames which have been elided due to tail recursive call optimizations.
func WithMaximumPhysicalStackHeight ¶
WithMaximumPhysicalStackHeight returns a Config that will prevent an execution environment from allowing the physical stack height to exceed n. The physical stack height is the literal number of frames in the call stack and does not account for stack frames elided due to tail recursive call optimizations.
func WithReader ¶
WithReader returns a Config that makes environments use r to parse source streams. There is no default Reader for an environment.
func WithStderr ¶
WithStderr returns a Config that makes environments write debugging output to w instead of the default, os.Stderr.
type ErrorVal ¶
type ErrorVal LVal
ErrorVal implements the error interface so that errors can be first class lisp objects. The error message is stored in the Str field while contextual information (e.g. call stack) can be stored in the Cells slice.
func (*ErrorVal) Error ¶
Error implements the error interface. When the error condition is not “error” it wil be printed preceding the error message. Otherwise, the name of the function that generated the error will be printed preceding the error, if the function can be determined.
func (*ErrorVal) ErrorMessage ¶
ErrorMessage returns the underlying message in the error.
type LBuiltinDef ¶
LBuiltinDef is a built-in function
func DefaultBuiltins ¶
func DefaultBuiltins() []LBuiltinDef
DefaultBuiltins returns the default set of LBuiltinDefs added to LEnv objects when LEnv.AddBuiltins is called without arguments.
func DefaultMacros ¶
func DefaultMacros() []LBuiltinDef
DefaultMacros returns the default set of LBuiltinDef added to LEnv objects when LEnv.AddMacros is called without arguments.
func DefaultSpecialOps ¶
func DefaultSpecialOps() []LBuiltinDef
DefaultSpecialOps returns the default set of LBuiltinDef added to LEnv objects when LEnv.AddSpecialOps is called without arguments.
type LEnv ¶
type LEnv struct { ID uint Loc *token.Location Scope map[string]*LVal FunName map[string]string Parent *LEnv Runtime *Runtime }
LEnv is a lisp environment.
func NewEnvRuntime ¶
NewEnvRuntime initializes a new LEnv, like NewEnv, but it explicitly specifies the runtime to use. NewEnvRuntime is only suitable for creating root LEnv object, so it does not take a parent argument. When rt is nil StandardRuntime() called to create a new Runtime for the returned LEnv. It is an error to use the same runtime object in multiple calls to NewEnvRuntime if the two envs are not in the same tree and doing so will have unspecified results.
func (*LEnv) AddBuiltins ¶
func (env *LEnv) AddBuiltins(external bool, funs ...LBuiltinDef)
AddBuiltins binds the given funs to their names in env. When called with no arguments AddBuiltins adds the DefaultBuiltins to env.
func (*LEnv) AddMacros ¶
func (env *LEnv) AddMacros(external bool, macs ...LBuiltinDef)
AddMacros binds the given macros to their names in env. When called with no arguments AddMacros adds the DefaultMacros to env.
func (*LEnv) AddSpecialOps ¶
func (env *LEnv) AddSpecialOps(external bool, ops ...LBuiltinDef)
AddSpecialOps binds the given special operators to their names in env. When called with no arguments AddSpecialOps adds the DefaultSpecialOps to env.
func (*LEnv) Copy ¶
Copy returns a new LEnv with a copy of env.Scope but a shared parent and stack (not quite a deep copy).
func (*LEnv) DefinePackage ¶
func (*LEnv) Error ¶
Error returns an LError value with an error message given by rendering msg.
Error may be called either with an error or with any number of *LVal values. It is invalid to pass an error argument with any other values and doing so will result in a runtime panic.
Unlike the exported function, the Error method returns LVal with a copy env.Runtime.Stack.
func (*LEnv) ErrorAssociate ¶
ErrorAssociate associates the LError value lerr with env's current call stack and source location. ErrorAssociate panics if lerr is not LError.
func (*LEnv) ErrorCondition ¶
ErrorCondition returns an LError the given condition type and an error message computed by rendering msg.
ErrorCondition may be called either with an error or with any number of *LVal values. It is invalid to pass ErrorCondition an error argument with any other values and doing so will result in a runtime panic.
Unlike the exported function, the ErrorCondition method returns an LVal with a copy env.Runtime.Stack.
func (*LEnv) ErrorConditionf ¶
ErrorConditionf returns an LError value with the given condition type and a a formatted error message rendered using fmt.Sprintf.
Unlike the exported function, the ErrorConditionf method returns an LVal with a copy env.Runtime.Stack.
func (*LEnv) Errorf ¶
Errorf returns an LError value with a formatted error message.
Unlike the exported function, the Errorf method returns an LVal with a copy env.Runtime.Stack.
func (*LEnv) Eval ¶
Eval evaluates v in the context (scope) of env and returns the resulting LVal. Eval does not modify v.
NOTE: Eval shouldn't unquote v during evaluation -- a difference between Eval and the “eval” builtin function, but it does. For some reason macros won't work without this unquoting.
func (*LEnv) GetFun ¶
GetFun returns a function referenced by the given LVal. If fun is already an LFun, then fun is returned. If fun is a symbol then GetFun looks for a function bound to the symbol. If fun does reference a symbol then an error is returned.
GetFun is a suitable for backing an implementation of functional programing constructs, like funcall, map, reduce, etc.
func (*LEnv) GetFunName ¶
GetFunName returns the function name (if any) known to be bound to the given FID.
func (*LEnv) GetGlobal ¶
GetGlobal takes LSymbol k and returns the value it is bound to in the current package.
func (*LEnv) Load ¶
Load reads LVals from r and evaluates them as if in a progn. The value returned by the last evaluated LVal will be retured. After evaluating expressions the current package is restored to the current package at the time Load was called, in case loaded source made calls to “in-package”. If env.Runtime.Reader has not been set then an error will be returned by Load.
func (*LEnv) LoadFile ¶
LoadFile attempts to use env.Runtime.Library to read a lisp source file and evaluate expressions it contains. Any error encountered will prevent execution of loaded source and be returned. After evaluating expressions the current package is restored to the current package at the time Load was called, in case loaded source made calls to “in-package”. If env.Runtime.Reader has not been set then an error will be returned by Load.
func (*LEnv) LoadLocation ¶
LoadLocation attempts to use env.Runtime.Library to read a lisp source file, specifying its name and location explicity, and evaluate the expressions it contains. Because the name and location of the stream are specfied explicitly LoadLocation does not depend explicity on an env.Runtime.Library implementation. Any error encountered will prevent execution of loaded source and be returned. After evaluating expressions the current package is restored to the current package at the time Load was called, in case loaded source made calls to “in-package”. If env.Runtime.Reader has not been set then an error will be returned by Load.
func (*LEnv) LoadString ¶
func (*LEnv) Put ¶
Put takes an LSymbol k and binds it to v in env. If k is already bound to a value the binding is updated so that k is bound to v.
func (*LEnv) SpecialOpCall ¶
SpecialOpCall invokes special operator fun with the argument list args.
func (*LEnv) Update ¶
Update updates the binding of k to v within the scope of env. Update can update either lexical or global bindings. If k is not bound by env, an enclosing LEnv, or the current package an error condition is signaled.
func (*LEnv) UsePackage ¶
type LFunType ¶
type LFunType uint8
LFunType denotes special functions, either macros or special operators.
type LType ¶
type LType uint
LType is the type of an LVal
const ( // LInvalid (0) is not a valid lisp type. LInvalid LType = iota // LInt values store an int in the LVal.Int field. LInt // LFloat values store a float64 in the LVal.Float field. LFloat // LError values use the LVal.Cells slice to store the following items: // [0] a symbol representing the error "condition" (class name) // [1:] error data (of any type) // // In addition, LError values store a copy of the function call stack at // the time of their creation in the LVal.Native field. // // TODO: Make the stack a first class type (or some composite type) so // that it could be inspected during a condition handler. LError // LSymbol values store a string representation of the symbol in the // LVal.Str field. LSymbol LQSymbol // TODO: Remove this... I can't believe it actually has usages // LSExpr values are "list" values in lisp and store their values in // LVal.Cells. LSExpr // LFun values use the following fields in an LVal: // LVal.Str a string containing a unique function identifier. // LVal.Native a reference to a native go function (LBuiltin) or a // lexical environment for a lisp-defined function. // LVal.FunType an enumerated value describing function evaluation // semantics (e.g. macro, special op, regular function). // LVal.Package the package the function is defined in. // // In addition to these fields, a function defined in lisp (with defun, // lambda, defmacro, etc) use the LVal.Cells field to store the following // items: // [0] a list describing the function's arguments // [1:] body expressions of the function (potentially no expressions) // // NOTE: Native go functions (LBuiltin) don't have a lexical environment // by default. If a native function needs a lexical environment in order // to evaluate further expressions it is expected to create one. See the // implementation of the builtin “let”. LFun // LQuote values are special values only used to represents two or more // levels of quoting (e.g. ”3 or ”””'()). The first level of quoting // takes places by setting the LVal.Quoted field on a value with a normal // value in LVal.Type. LQuote values must always have a true LVal.Quoted // field. LQuote // LString values store a string in the LVal.Str field. LString // LBytes values store a *[]byte in the LVal.Native field. LVal.Native, // and the contained pointer, must must never be nil (the slice being // pointed to may be nil though). LBytes // LSortMap value uses the LVal.Map field to store a map. // // TODO: Use a tree-based map (that is potentially stored in Cells). A // tree based map would be capable of supporting integer keys. LSortMap // LArray values use the LVal.Cells slice to store the following items: // [0] a list containing dimension cardinalities in index 0 // [1] a list containing row-major ordered array values LArray // LNative values store a Go value in the LVal.Native field and can be used // by builtin functions store references to values of any type. LNative // Mark LVals are used to trasmit information down the stack through return // values. Because the LEnv does not evaluate expressions using a stack // based virtual machine these Mark values, which often wrap other LVal // data in their Cells, are passed back from functions. Typically the // environment is solely responsible for managing mark values and // applications should never see them during calls to builtin functions. LMarkTerminal // LEnv marks the frame as terminal and evaluates tho contained expr LMarkTailRec // LEnv resumes a call a set number of frames down the stack. LMarkMacExpand // LEnv will evaluate the returned LVal a subsequent time. )
Possible LValType values
type LVal ¶
type LVal struct { // Type is the native type for a value in lisp. Type LType // Source is the values originating location in source code. Source *token.Location // Fields used for numeric types Int int Float float64 // Str used by LSymbol and LString values Str string // Cells used by many values as a storage space for lisp objects. // // TODO: Consider making Cells' type []LVal instead of []*LVal to reduce // the burden on the allocator/gc. Cells []*LVal // Native is generic storage for data which cannot be represented as an // LVal (and thus can't be stored in Cells). Native interface{} // FunType used to further classify LFun values FunType LFunType Quoted bool // flag indicating a single level of quoting Spliced bool // denote the value as needing to be spliced into a parent value }
LVal is a lisp value
func Array ¶
Array returns an LVal representing an array reference. The dims argument is be a list of integers sizes for each dimension of the array. If non-empty, cells provides the backing storage for the array. The dims argument may be nil, in which case a vector (one dimensional array) is returned. If dims is non-nil then cells must either be nil or have one element for every array element, in row-major order.
func Error ¶
Error returns an LError representing err. Errors store their message in Cells and their condition type in Str. The error condition type must be a valid lisp symbol.
Errors generated during expression evaluation typically have a non-nil Stack field. The Env.Error() method is typically the preferred method for creating error LVal objects because it initializes Stack with an appropriate value.
func ErrorCondition ¶
ErrorCondition returns an LError representing err and having the given condition type. Errors store their message/data in Cells and their condition type in Str. The condition type must be a valid lisp symbol.
Errors generated during expression evaluation typically have a non-nil Stack field. The Env.Error() method is typically the preferred method for creating error LVal objects because it initializes Stack with an appropriate value.
func ErrorConditionf ¶
ErrorConditionf returns an LError with a formatted error message. Errors store their message in Cells and their condition type in Str. The condition type must be a valid symbol.
Errors generated during expression evaluation typically have a non-nil Stack field. The Env.ErrorConditionf() method is typically the preferred method for creating error LVal objects because it initializes Stack with an appropriate value.
func Errorf ¶
Errorf returns an LError with a formatted error message. Errors store their message in Cells and their condition type in Str. The condition type must be a valid symbol.
Errors generated during expression evaluation typically have a non-nil Stack field. The Env.Errorf() method is typically the preferred method for creating error LVal objects because it initializes Stack with an appropriate value.
func Formals ¶
Formals returns an LVal reprsenting a function's formal argument list containing symbols with the given names.
func InitializeUserEnv ¶
InitializeUserEnv creates the default user environment.
func QExpr ¶
QExpr returns an LVal representing an Q-expression, a quoted expression, a list. Provided cells are used as backing storage for the returned list and are not copied.
func SExpr ¶
SExpr returns an LVal representing an S-expression, a symbolic expression. Provided cells are used as backing storage for the returned expression and are not copied.
func SpecialOp ¶
SpecialOp returns an LVal representing a special operator. Special operators are function which receive unevaluated results, like macros. However values returned by special operations do not require further evaluation, unlike macros.
func Splice ¶
Splice is used in the implementation of quasiquote to insert a list into an outer slist.
func Value ¶
func Value(v interface{}) *LVal
Value conveniently converts v to an LVal. Types which can be represented directly in lisp will be converted to the appropriate LVal. All other types will be turned into a Native LVal. Value is the GoValue function.
func (*LVal) ArrayDims ¶
ArrayDims returns the dimensions of an array. ArrayDims panics if v.Type is not LArray
func (*LVal) ArrayIndex ¶
ArrayIndex returns the value at
func (*LVal) Equal ¶
Equal returns a non-nil value if v and other are logically equal, under the rules used by the “equal?” function.
BUG: sorted-map comparison is not implemented
func (*LVal) IsMacro ¶
IsMacro returns true if v is a macro function. IsMacro doesn't actually check v.Type, only v.FunType.
func (*LVal) IsSpecialFun ¶
IsSpecialFun returns true if v is a special function. IsSpecialFun doesn't actually check v.Type, only v.FunType.
func (*LVal) IsSpecialOp ¶
IsSpecialOp returns true if v is a special operator. IsMacro doesn't actually check v.Type, only v.FunType.
func (*LVal) MapGet ¶
MapGet returns the value corresponding to k in v or an LError if k is not present in v. MapGet panics if v.Type is not LSortMap.
func (*LVal) MapKeys ¶
MapKeys returns a list of keys in the map. MapKeys panics if v.Type is not LSortMap. The type of each map key is retained from the first type a value was set for that key. For example, if the MapSet(Symbol("a"), Int(1)) is called before MapSet(String("a"), Int(2)) then MapKey() will contain the symbol and not the string.
func (*LVal) MapSet ¶
MapSet sets k to val in v. MapSet panics if v.Type is not LSortMap. String and symbol keys are coerced to avoid programming errors causing symbol and string keys with equal string values from existing in the same map.
func (*LVal) SetCallStack ¶
type Loader ¶
func LoaderMust ¶
LoaderMust returns its first argument when err is nil. If err is nil LoaderMust panics.
func TextLoader ¶
TextLoader parses a text stream using r and returns a Loader which evaluates the stream's expressions when called. The reader will be invoked only once. TextLoader will return an error if r produces any reference types (bytes, map, array, native, etc).
type LocationReader ¶
type LocationReader interface { // ReadLocation the contents of r, associated with physical location loc, // and return the sequence of LVals that it contains. The returned LVals // should be executed as if inside a progn. ReadLocation(name string, loc string, r io.Reader) ([]*LVal, error) }
LocationReader is like Reader but assigns physical locations to the tokens from r.
type LogicalStackOverflowError ¶
type LogicalStackOverflowError struct {
Height int
}
func (*LogicalStackOverflowError) Error ¶
func (e *LogicalStackOverflowError) Error() string
type Package ¶
type Package struct { Name string Symbols map[string]*LVal FunNames map[string]string Externals []string }
Package is a named set of bound symbols. A package is interpreted code and belongs to the LEnv that creates it.
func NewPackage ¶
NewPackage initializes and returns a package with the given name.
func (*Package) Exports ¶
Exports declares symbols exported by the package. The symbols are not required to be bound at the time Exports is called.
func (*Package) GetFunName ¶
GetFunName returns the function name (if any) known to be bound to the given FID.
type PackageRegistry ¶
type PackageRegistry struct { Packages map[string]*Package Lang string // A default package used by all other packages }
PackageRegistry contains a set of packages.
func NewRegistry ¶
func NewRegistry() *PackageRegistry
NewRegistry initializes and returns a new PackageRegistry.
func (*PackageRegistry) DefinePackage ¶
func (r *PackageRegistry) DefinePackage(name string) *Package
type PhysicalStackOverflowError ¶
type PhysicalStackOverflowError struct {
Height int
}
func (*PhysicalStackOverflowError) Error ¶
func (e *PhysicalStackOverflowError) Error() string
type Reader ¶
type Reader interface { // Read the contents of r and return the sequence of LVals that it // contains. The returned LVals should be executed as if inside a progn. Read(name string, r io.Reader) ([]*LVal, error) }
Reader abstracts a parser implementation so that it may be implemented in a separate package as an optional/swappable component.
type RelativeFileSystemLibrary ¶
type RelativeFileSystemLibrary struct { }
RelativeFileSystemLibrary implements SourceLibrary and reads lisp source files from the filesystem, relative to the source context location.
In order to read filepaths relative to a source file's location the application's implementation of Runtime.Reader must implement LocationReader.
func (*RelativeFileSystemLibrary) LoadSource ¶
func (lib *RelativeFileSystemLibrary) LoadSource(ctx SourceContext, loc string) (string, string, []byte, error)
LoadSource attempts to open loc as a filepath.
type Runtime ¶
type Runtime struct { Registry *PackageRegistry Package *Package Stderr io.Writer Stack *CallStack Reader Reader Library SourceLibrary // contains filtered or unexported fields }
Runtime is an object underlying a family of tree of LEnv values. It is responsible for holding shared environment state, generating identifiers, and writing debugging output to a stream (typically os.Stderr).
func StandardRuntime ¶
func StandardRuntime() *Runtime
StandardRuntime returns a new Runtime with an empty package registry and Stderr set to os.Stderr.
type SourceContext ¶
type SourceContext interface { // Name is the name of the current source stream being evaluated which // caused the SourceLibrary LoadLocation operation. Name is like Location // but is not necessarily tied to a physical location, or otherwise may be // ambiguous. // // NOTE: Name may not be generated by the Runtime SourceLibrary due to // functions being sourced externally (in particular, the core language and // application standard library). As such, the Name of a SourceContext is // meant only for informal use to assist humans and should not be relied // upon by a SourceLibrary. Name() string // Location is the current source location (e.g. file path) being evaluated // which caused the SourceLibrary LoadSource operation. This may be used // in determining the location of relative target source locations. If // executing code is not sourced from a lisp file then Location will return // an empty string -- this includes LoadSource operations triggered from // native Go functions and raw strings/[]bytes containing lisp code. // SourceLibraries should interpret an empty Location string as the process // working directory. Location() string }
SourceContext provides an execution context allowing SourceLibraries flexibility in determining how to interpret a path.
NOTE: SourceContext may be expanded with new methods yielding externally defined implementations incompatible.
type SourceLibrary ¶
type SourceLibrary interface { // LoadSource returns the data contained in the source file specified by a // location string obtained through a user call. For example, the call // `(load-file "foo.txt")` would pass loc "foo.txt" to LoadSource). // LoadSource also receives a SourceContext object which may be used to // determine the physical path to the target location (e.g. what file is // loading "foo.txt"?). // // LoadSource returns four values: a name and true-location unambiguously // identifying the file, the file data, and any error that occurred while // retrieving data. An interpreter must use trueloc as an identifier for // the requested source file anywhere the SourceContext ctx is unavailable. LoadSource(ctx SourceContext, loc string) (name, trueloc string, data []byte, err error) }
SourceLibrary is responsible for loading source code from a given path. It is up to the SourceLibrary implementation how a source location should be interpreted. Depending on the application a SourceLibrary implementation may require a Runtime with Reader that implements LocationReader -- though the LocationReader implementation should not need to depend on the LocationReader implementation beyond that.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package lisplib is used to conveniently load the standard library for the elps environment
|
Package lisplib is used to conveniently load the standard library for the elps environment |