added "symbol?"

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

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

@ -132,3 +132,12 @@ func isnull(vals []interface{}) (interface{}, error) {
return len(s) == 0, nil 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,9 +21,12 @@ func (s sexp) String() string {
type symbol string type symbol string
var universe = &environment{map[symbol]interface{}{ var universe = &environment{map[symbol]interface{}{
// predefined values
"#t": true, "#t": true,
"#f": false, "#f": false,
"null": nil, "null": nil,
// builtin functions
"+": builtin(addition), "+": builtin(addition),
"-": builtin(subtraction), "-": builtin(subtraction),
"*": builtin(multiplication), "*": builtin(multiplication),
@ -33,6 +36,9 @@ var universe = &environment{map[symbol]interface{}{
"list?": builtin(islist), "list?": builtin(islist),
"not": builtin(not), "not": builtin(not),
"null?": builtin(isnull), "null?": builtin(isnull),
"symbol?": builtin(issymbol),
// special forms
"begin": special(begin), "begin": special(begin),
"define": special(define), "define": special(define),
"if": special(_if), "if": special(_if),

Loading…
Cancel
Save