|
|
@ -23,6 +23,7 @@ type symbol string
|
|
|
|
var universe = &environment{map[symbol]interface{}{
|
|
|
|
var universe = &environment{map[symbol]interface{}{
|
|
|
|
"#t": true,
|
|
|
|
"#t": true,
|
|
|
|
"#f": false,
|
|
|
|
"#f": false,
|
|
|
|
|
|
|
|
"null": nil,
|
|
|
|
"+": builtin(addition),
|
|
|
|
"+": builtin(addition),
|
|
|
|
"-": builtin(subtraction),
|
|
|
|
"-": builtin(subtraction),
|
|
|
|
"*": builtin(multiplication),
|
|
|
|
"*": builtin(multiplication),
|
|
|
@ -31,6 +32,7 @@ var universe = &environment{map[symbol]interface{}{
|
|
|
|
"list": builtin(list),
|
|
|
|
"list": builtin(list),
|
|
|
|
"list?": builtin(islist),
|
|
|
|
"list?": builtin(islist),
|
|
|
|
"not": builtin(not),
|
|
|
|
"not": builtin(not),
|
|
|
|
|
|
|
|
"null?": builtin(isnull),
|
|
|
|
"begin": special(begin),
|
|
|
|
"begin": special(begin),
|
|
|
|
"define": special(define),
|
|
|
|
"define": special(define),
|
|
|
|
"if": special(_if),
|
|
|
|
"if": special(_if),
|
|
|
@ -109,6 +111,10 @@ func parse(c chan token) (interface{}, error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func eval(v interface{}, env *environment) (interface{}, error) {
|
|
|
|
func eval(v interface{}, env *environment) (interface{}, error) {
|
|
|
|
|
|
|
|
if v == nil {
|
|
|
|
|
|
|
|
return sexp{}, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch t := v.(type) {
|
|
|
|
switch t := v.(type) {
|
|
|
|
|
|
|
|
|
|
|
|
case symbol:
|
|
|
|
case symbol:
|
|
|
@ -163,7 +169,8 @@ func eval(v interface{}, env *environment) (interface{}, error) {
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
return v, nil
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
|
|
|
|
|
|
|
|
panic("not reached")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func evalall(c chan token, env *environment) {
|
|
|
|
func evalall(c chan token, env *environment) {
|
|
|
|