Documentation ¶
Index ¶
- Variables
- func IsBoolean(exp Expression) bool
- func IsLambdaType(expression Expression) bool
- func IsNilObj(obj Expression) bool
- func IsNullExp(exp Expression) bool
- func IsNumber(exp Expression) bool
- func IsPair(obj Expression) bool
- func IsPrimitiveExpression(exp Expression) bool
- func IsQuote(exp Expression) bool
- func IsString(exp Expression) bool
- func IsSymbol(expression Expression) bool
- func IsSyntaxExpression(exp Expression) bool
- func IsThunk(exp Expression) bool
- func IsTrue(exp Expression) bool
- func IsUndefObj(obj Expression) bool
- func Tokenize(inputScript string) []string
- type Env
- type Expression
- type Function
- type Interpreter
- type InterpreterMode
- type LambdaProcess
- type NilType
- type Number
- type Pair
- type Quote
- type String
- type Symbol
- type Syntax
- type SyntaxFunc
- type Thunk
- type Tokenizer
- type Undef
Constants ¶
This section is empty.
Variables ¶
var NilObj = NilType{}
NilObj is the common object of NilType
var SyntaxMap = make(map[string]*Syntax)
SyntaxMap contains all defined scheme syntax.
var UndefObj = Undef{}
UndefObj is the common Undef object.
Functions ¶
func IsBoolean ¶
func IsBoolean(exp Expression) bool
IsBoolean return true if the expression represents bool.
func IsLambdaType ¶
func IsLambdaType(expression Expression) bool
IsLambdaType checks whether this expression low level value is *LambdaProcess
func IsNilObj ¶
func IsNilObj(obj Expression) bool
IsNilObj returns true when the expression is NilTyp.
func IsNullExp ¶
func IsNullExp(exp Expression) bool
IsNullExp checks whether the expression represents Null(nil, NilType, blank list, blank expression).
func IsNumber ¶
func IsNumber(exp Expression) bool
IsNumber check whether the expression represents Number.
func IsPair ¶
func IsPair(obj Expression) bool
IsPair checks whether the expression value is a *Pair.
func IsPrimitiveExpression ¶
func IsPrimitiveExpression(exp Expression) bool
IsPrimitiveExpression checks whether the expressions value is the primitive types.
func IsString ¶
func IsString(exp Expression) bool
IsString check whether the expression represents String in scheme.
func IsSymbol ¶
func IsSymbol(expression Expression) bool
IsSymbol checks whether the expression is Symbol.
func IsSyntaxExpression ¶
func IsSyntaxExpression(exp Expression) bool
IsSyntaxExpression check whether the expression is a scheme syntax expression.
func IsThunk ¶
func IsThunk(exp Expression) bool
IsThunk checks whether an expression is a thunk and return the result
func IsTrue ¶
func IsTrue(exp Expression) bool
IsTrue check whether the condition is true. Return false when Exp is #f or false, otherwise return true
func IsUndefObj ¶
func IsUndefObj(obj Expression) bool
IsUndefObj returns true when the expression is Undef.
Types ¶
type Env ¶
type Env struct {
// contains filtered or unexported fields
}
Env represents the context of code.
func (*Env) Find ¶
func (e *Env) Find(symbol Symbol) (Expression, error)
Find search all the relative environments to find the variable matching symbol.
func (*Env) Set ¶
func (e *Env) Set(symbol Symbol, value Expression)
Set a symbol and its value in current environment
type Expression ¶
type Expression interface{}
Expression represent the parsed tokens of scheme syntax tree or the low level builtin types.
func ActualValue ¶
func ActualValue(exp Expression) (Expression, error)
ActualValue returns the actual value of an expression. If the expression is a Thunk, eval and return the result, otherwise return the expression itself.
func Eval ¶
func Eval(exp Expression, env *Env) (ret Expression, err error)
Eval is the main function to evaluate the expression in an environment.
func EvalAll ¶
func EvalAll(exps []Expression, env *Env) (ret Expression, err error)
EvalAll iterate the sequence of expressions and evaluate each one. Returns the last evaluated value as the result
func Parse ¶
func Parse(tokens *[]string) (ret []Expression, err error)
Parse read and parse the tokens to construct a syntax tree represents in nested slices.
type Function ¶
type Function struct {
// contains filtered or unexported fields
}
Function represents the basic scheme function in pure go.
func NewFunction ¶
NewFunction return a Function struct init with arguments. minArgs, maxArgs define the arguments count limitation of Function. Set to -1 means no limitation.
func (Function) Call ¶
func (f Function) Call(args ...Expression) (Expression, error)
Call eval the function with args and returns the result.
type Interpreter ¶
type Interpreter struct {
// contains filtered or unexported fields
}
Interpreter read from source and evaluate them.
func NewFileInterpreter ¶
func NewFileInterpreter(reader io.Reader) *Interpreter
NewFileInterpreter construct a *Interpreter from file.
func NewFileInterpreterWithEnv ¶
func NewFileInterpreterWithEnv(reader io.Reader, env *Env) *Interpreter
NewFileInterpreterWithEnv construct a *Interpreter from io.reader init with env.
func NewREPLInterpreter ¶
func NewREPLInterpreter() *Interpreter
NewREPLInterpreter construct a REPL *Interpreter.
func (*Interpreter) Run ¶
func (i *Interpreter) Run() (err error)
Run start the interpreter and evaluate the input.
type InterpreterMode ¶
type InterpreterMode uint8
InterpreterMode represents mode the interpreter will run
const ( // Interactive set the interpreter running as interactive shell Interactive InterpreterMode = iota // NoneInteractive set the interpreter running in normal mode without shell. NoneInteractive )
type LambdaProcess ¶
type LambdaProcess struct {
// contains filtered or unexported fields
}
LambdaProcess wraps the body and env of a lambda expression
func (*LambdaProcess) Body ¶
func (lambda *LambdaProcess) Body() Expression
Body returns the expressions of body.
func (*LambdaProcess) String ¶
func (lambda *LambdaProcess) String() string
String implements the stringer interface
type Pair ¶
type Pair struct {
Car, Cdr Expression
}
Pair combines the two values. Should only use with pointer
type Syntax ¶
type Syntax struct {
// contains filtered or unexported fields
}
Syntax wrap a syntax and give method to eval it.
func NewSyntax ¶
func NewSyntax(name string, fn SyntaxFunc) *Syntax
NewSyntax construct a Syntax with custom name and SyntaxFunc
func (*Syntax) Eval ¶
func (s *Syntax) Eval(args []Expression, env *Env) (Expression, error)
Eval runs the syntax and return the result.
type SyntaxFunc ¶
type SyntaxFunc func(args []Expression, env *Env) (Expression, error)
SyntaxFunc specified the common func format for Syntax
type Thunk ¶
type Thunk struct { // expression to execute Exp Expression // context to execute Exp Env *Env // contains filtered or unexported fields }
Thunk wraps expression for lazy execution Thunk should use as pointer
func NewThunk ¶
func NewThunk(exp Expression, env *Env) *Thunk
NewThunk creates a thunk and returns the pointer
func (*Thunk) Value ¶
func (t *Thunk) Value() (Expression, error)
Value returns the actual value of the thunk
type Tokenizer ¶
Tokenizer wraps the input to generate tokens.
func NewTokenizerFromReader ¶
NewTokenizerFromReader construct *Tokenizer from io.Reader
func NewTokenizerFromString ¶
NewTokenizerFromString construct *Tokenizer from string