Permalink
Browse files

support and test for lambda-one

  • Loading branch information...
1 parent 7ac803a commit 0ab1bde6afd839ec9ccc54a96ddf17b010028b3e @ajb committed May 7, 2012
Showing with 13 additions and 0 deletions.
  1. +8 −0 Homework5/scheem.js
  2. +5 −0 Homework5/test/evalScheemTest.js
View
@@ -108,6 +108,14 @@ var evalScheem = function (expr, env) {
} else {
return evalScheem(expr[3], env);
}
+ case 'lambda-one':
+ // New code here
+ return function(arg){
+ var binding = {};
+ binding[expr[1]] = arg;
+ var newEnv = {bindings: binding, outer: env};
+ return evalScheem(expr[2], newEnv);
+ };
default:
var func = evalScheem(expr[0], env);
var args = expr;
@@ -39,6 +39,11 @@ suite('scheem', function(){
evalSchemeString('(add_three 1 2 3)', {}), 6);
});
+ test('lambda-one', function() {
+ assert.deepEqual(
+ evalSchemeString('(begin (define add_two (lambda-one x (+ x 2) ) ) (add_two 2) )', {}), 4);
+ });
+
});

0 comments on commit 0ab1bde

Please sign in to comment.