added "symbol?"

master
Jordan Orelli 12 years ago
parent 699c407c22
commit 591a0bfe29

@ -70,3 +70,6 @@ x
(null? (quote ()))
(null? (list))
(symbol? (quote null))
(symbol? 1)

@ -132,3 +132,12 @@ func isnull(vals []interface{}) (interface{}, error) {
return len(s) == 0, nil
}
func issymbol(vals []interface{}) (interface{}, error) {
if err := checkArity(1, vals, "symbol?"); err != nil {
return nil, err
}
_, ok := vals[0].(symbol)
return ok, nil
}

@ -21,18 +21,24 @@ func (s sexp) String() string {
type symbol string
var universe = &environment{map[symbol]interface{}{
"#t": true,
"#f": false,
"null": nil,
"+": builtin(addition),
"-": builtin(subtraction),
"*": builtin(multiplication),
"/": builtin(division),
"length": builtin(length),
"list": builtin(list),
"list?": builtin(islist),
"not": builtin(not),
"null?": builtin(isnull),
// predefined values
"#t": true,
"#f": false,
"null": nil,
// builtin functions
"+": builtin(addition),
"-": builtin(subtraction),
"*": builtin(multiplication),
"/": builtin(division),
"length": builtin(length),
"list": builtin(list),
"list?": builtin(islist),
"not": builtin(not),
"null?": builtin(isnull),
"symbol?": builtin(issymbol),
// special forms
"begin": special(begin),
"define": special(define),
"if": special(_if),

Loading…
Cancel
Save