diff --git a/input.scm b/input.scm index 31150b3..aa37c02 100644 --- a/input.scm +++ b/input.scm @@ -52,3 +52,4 @@ x (define a1 (make-account 100.00)) (a1 -20.00) + diff --git a/proc.go b/proc.go index 3da45a5..76951e0 100644 --- a/proc.go +++ b/proc.go @@ -83,3 +83,10 @@ func division(vals []interface{}) (interface{}, error) { } return a.total(vals) } + +func not(vals []interface{}) (interface{}, error) { + if err := checkArity(1, vals, "not"); err != nil { + return nil, err + } + return !booleanize(vals[0]), nil +} diff --git a/skeam.go b/skeam.go index 324256b..d4db98f 100644 --- a/skeam.go +++ b/skeam.go @@ -27,6 +27,7 @@ var universe = &environment{map[symbol]interface{}{ "-": builtin(subtraction), "*": builtin(multiplication), "/": builtin(division), + "not": builtin(not), "define": special(define), "quote": special(quote), "if": special(_if), diff --git a/special.go b/special.go index efdbb19..a261b0c 100644 --- a/special.go +++ b/special.go @@ -71,6 +71,13 @@ func quote(_ *environment, args ...interface{}) (interface{}, error) { return args[0], nil } +func booleanize(v interface{}) bool { + if b, ok := v.(bool); ok { + return b + } + return true +} + // defines the built-in "if" contruct. e.g.: // // (if #t "foo" "bar") @@ -90,10 +97,10 @@ func _if(env *environment, args ...interface{}) (interface{}, error) { return nil, err } - if b, ok := v.(bool); ok && !b { - return eval(args[2], env) + if booleanize(v) { + return eval(args[1], env) } - return eval(args[1], env) + return eval(args[2], env) } // defines the built-in "set" construct, which is used to set the value of an