added "null" and "null?"

master
Jordan Orelli 12 years ago
parent 86c288d116
commit ee8a7d3ee5

@ -119,3 +119,16 @@ func islist(vals []interface{}) (interface{}, error) {
_, ok := vals[0].(sexp)
return ok, nil
}
func isnull(vals []interface{}) (interface{}, error) {
if err := checkArity(1, vals, "null?"); err != nil {
return nil, err
}
s, ok := vals[0].(sexp)
if !ok {
return false, nil
}
return len(s) == 0, nil
}

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

Loading…
Cancel
Save