From 175e8abf1bae04e78103ea9e43d0d246a57c39f6 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sun, 21 Oct 2012 13:25:34 -0400 Subject: [PATCH] added "begin" special form --- input.scm | 10 ++++++++++ skeam.go | 1 + special.go | 15 +++++++++++++++ 3 files changed, 26 insertions(+) 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 +}