diff --git a/input.scm b/input.scm index 5f979a5..31150b3 100644 --- a/input.scm +++ b/input.scm @@ -42,3 +42,13 @@ x (plusone 1) ((lambda (x) (* x x)) 4) + +((lambda (x y) (+ x y)) 10 25) + +(define make-account + (lambda (balance) + (lambda (amt) + (begin (set! balance (+ balance amt)) balance)))) + +(define a1 (make-account 100.00)) +(a1 -20.00) diff --git a/skeam.go b/skeam.go index f3290a5..324256b 100644 --- a/skeam.go +++ b/skeam.go @@ -32,6 +32,7 @@ var universe = &environment{map[symbol]interface{}{ "if": special(_if), "set!": special(set), "lambda": special(mklambda), + "begin": special(begin), }, nil} // parses the string lexeme into a value that can be eval'd diff --git a/special.go b/special.go index 412fef5..efdbb19 100644 --- a/special.go +++ b/special.go @@ -187,3 +187,18 @@ func mklambda(env *environment, args ...interface{}) (interface{}, error) { return lambda{env, arglabels, body}, nil } + +func begin(env *environment, args ...interface{}) (interface{}, error) { + debugPrint("begin") + + var err error + var v interface{} + for _, arg := range args { + v, err = eval(arg, env) + if err != nil { + return nil, err + } + } + + return v, nil +}