diff --git a/input.scm b/input.scm index aa37c02..d24d094 100644 --- a/input.scm +++ b/input.scm @@ -53,3 +53,7 @@ x (define a1 (make-account 100.00)) (a1 -20.00) +(not "dave") +(if (not #f) (quote "true-condition") (quote "false-condition")) + +(length (quote (1 2 3))) diff --git a/proc.go b/proc.go index 76951e0..2906dfb 100644 --- a/proc.go +++ b/proc.go @@ -2,6 +2,8 @@ package main import ( "errors" + "fmt" + "reflect" ) type builtin func([]interface{}) (interface{}, error) @@ -90,3 +92,21 @@ func not(vals []interface{}) (interface{}, error) { } return !booleanize(vals[0]), nil } + +func length(vals []interface{}) (interface{}, error) { + if err := checkArity(1, vals, "length"); err != nil { + return nil, err + } + + x, ok := vals[0].(sexp) + if !ok { + return nil, fmt.Errorf("first argument must be sexp, received %v", reflect.TypeOf(vals[0])) + } + return len(x), nil +} + +/* +func car(vals []interface{}) (interface{}, error) { + +} +*/ diff --git a/skeam.go b/skeam.go index d4db98f..277f2f6 100644 --- a/skeam.go +++ b/skeam.go @@ -27,6 +27,7 @@ var universe = &environment{map[symbol]interface{}{ "-": builtin(subtraction), "*": builtin(multiplication), "/": builtin(division), + "length": builtin(length), "not": builtin(not), "define": special(define), "quote": special(quote),