Documentation ¶
Index ¶
- Variables
- func AtomParser(st ParseState) (interface{}, error)
- func LambdaExpr(env Env) element
- func LetExpr(env Env) element
- func ListParser(st ParseState) (interface{}, error)
- func NumberParser(st ParseState) (interface{}, error)
- func QuoteParser(st ParseState) (interface{}, error)
- func ValueParser(st ParseState) (interface{}, error)
- type Atom
- type Env
- type Environment
- type Function
- func (this Function) Define(name string, value interface{}) error
- func (this Function) Eval(env Env) (interface{}, error)
- func (this Function) Global(name string) (interface{}, bool)
- func (this Function) Local(name string) (interface{}, bool)
- func (this Function) Lookup(name string) (interface{}, bool)
- func (this Function) Parameter(name string) (interface{}, bool)
- func (this Function) SetVar(name string, value interface{}) error
- type GispParser
- func (this GispParser) Define(name string, value interface{}) error
- func (this GispParser) Global(name string) (interface{}, bool)
- func (this GispParser) Local(name string) (interface{}, bool)
- func (this GispParser) Lookup(name string) (interface{}, bool)
- func (this GispParser) Parse(code string) (interface{}, error)
- func (this GispParser) SetVar(name string, value interface{}) error
- type Lambda
- type Let
- func (this Let) Define(name string, value interface{}) error
- func (this Let) Eval(env Env) (interface{}, error)
- func (this Let) Global(name string) (interface{}, bool)
- func (this Let) Local(name string) (interface{}, bool)
- func (this Let) Lookup(name string) (interface{}, bool)
- func (this Let) SetVar(name string, value interface{}) error
- type Lisp
- type List
- type Quote
Constants ¶
This section is empty.
Variables ¶
View Source
var Axiom = Environment{ Meta: map[string]interface{}{ "name": "axiom", "category": "environment", }, Content: map[string]function{ "quote": func(env Env) element { return func(args ...interface{}) (interface{}, error) { return Quote{args[0]}, nil } }, "var": func(env Env) element { return func(args ...interface{}) (interface{}, error) { value, err := eval(env, args[1]) if err != nil { return nil, err } err = env.Define((args[0].(Atom)).Name, value) return nil, err } }, "set": func(env Env) element { return func(args ...interface{}) (interface{}, error) { value, err := eval(env, args[1]) if err != nil { return nil, err } err = env.SetVar((args[0].(Atom)).Name, value) if err == nil { return nil, err } else { return value, nil } } }, "equal": func(env Env) element { return func(args ...interface{}) (interface{}, error) { x, err := eval(env, args[0]) if err != nil { return nil, err } y, err := eval(env, args[1]) if err != nil { return nil, err } return reflect.DeepEqual(x, y), nil } }, "cond": func(env Env) element { return func(args ...interface{}) (interface{}, error) { cases := args[0].([]interface{}) l := len(args) var els interface{} if l > 1 { els = args[1] } else { els = nil } for _, b := range cases { branch := b.([]interface{}) cond := branch[0].(List) result, err := eval(env, cond) if err != nil { return nil, err } if ok := result.(bool); ok { return eval(env, branch[1]) } } if els != nil { return eval(env, els) } else { return nil, nil } } }, "car": func(env Env) element { return func(args ...interface{}) (interface{}, error) { lisp, err := eval(env, args[0]) if err != nil { return nil, err } return (lisp.(List))[0], nil } }, "cdr": func(env Env) element { return func(args ...interface{}) (interface{}, error) { lisp, err := eval(env, args[0]) if err != nil { return nil, err } return (lisp.(List))[1:], nil } }, "atom": func(env Env) element { return func(args ...interface{}) (interface{}, error) { arg := args[0] if l, ok := arg.(List); ok { return len(l) == 0, nil } else { return true, nil } } }, "concat": func(env Env) element { return func(args ...interface{}) (interface{}, error) { return List(args), nil } }, }, }
View Source
var BoolParser = Bind(Choice(String("true"), String("false")), func(input interface{}) Parser { return func(st ParseState) (interface{}, error) { switch input.(string) { case "true": return true, nil case "false": return false, nil default: return nil, fmt.Errorf("Unexpect bool token %v", input) } } })
View Source
var EscapeChar = Bind_(Rune('\\'), func(st ParseState) (interface{}, error) { r, err := OneOf("nrt\"\\")(st) if err == nil { ru := r.(rune) switch ru { case 'r': return '\r', nil case 'n': return '\n', nil case '\'': return '\'', nil case '"': return '"', nil case '\\': return '\\', nil case 't': return '\t', nil default: return nil, st.Trap("Unknown escape sequence \\%c", r) } } else { return nil, err } })
View Source
var NilParser = Bind_(String("nil"), Return(nil))
View Source
var RuneParser = Bind( Between(Rune('\''), Rune('\''), Either(Try(EscapeChar), NoneOf("'"))), ReturnString)
View Source
var StringParser = Bind( Between(Rune('"'), Rune('"'), Many(Either(Try(EscapeChar), NoneOf("\"")))), ReturnString)
Functions ¶
func AtomParser ¶
func AtomParser(st ParseState) (interface{}, error)
func LambdaExpr ¶
func LambdaExpr(env Env) element
func ListParser ¶
func ListParser(st ParseState) (interface{}, error)
func NumberParser ¶
func NumberParser(st ParseState) (interface{}, error)
func QuoteParser ¶
func QuoteParser(st ParseState) (interface{}, error)
func ValueParser ¶
func ValueParser(st ParseState) (interface{}, error)
Types ¶
type Environment ¶
var Propositions Environment = Environment{ Meta: map[string]interface{}{ "name": "propositions", "category": "environment", }, Content: map[string]function{ "lambda": LambdaExpr, "let": LetExpr, "+": addExpr, "add": addExpr, "-": subExpr, "sub": subExpr, "*": mulExpr, "mul": mulExpr, "/": divExpr, "div": divExpr, }, }
func (Environment) Global ¶
func (this Environment) Global(name string) (interface{}, bool)
func (Environment) Local ¶
func (this Environment) Local(name string) (interface{}, bool)
func (Environment) Lookup ¶
func (this Environment) Lookup(name string) (interface{}, bool)
type GispParser ¶
func (GispParser) Define ¶
func (this GispParser) Define(name string, value interface{}) error
func (GispParser) Global ¶
func (this GispParser) Global(name string) (interface{}, bool)
look up in buildins
func (GispParser) Local ¶
func (this GispParser) Local(name string) (interface{}, bool)
func (GispParser) Lookup ¶
func (this GispParser) Lookup(name string) (interface{}, bool)
func (GispParser) Parse ¶
func (this GispParser) Parse(code string) (interface{}, error)
func (GispParser) SetVar ¶
func (this GispParser) SetVar(name string, value interface{}) error
type Lambda ¶
func DeclareLambda ¶
(lambda (args...) body)
Click to show internal directories.
Click to hide internal directories.