added "begin" special form

master
Jordan Orelli 12 years ago
parent b023686c81
commit 175e8abf1b

@ -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)

@ -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

@ -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
}

Loading…
Cancel
Save