Array.prototype.contains = function(obj) { var i, listed = false; for (i=0; i=0;i--) { list = new Pair(arguments[i],list); } return list; } function is_list(obj) { if (is_null(obj)) { return true; } else if (is_pair(obj)) { if (is_null(cdr(obj))) { return true; } else if (is_pair(cdr(obj))) { return is_list(cdr(obj)); } else { return false; } } else { return false; } } function sym(name) { return new Symbol(name); } // +++ Native Methods +++ function Native_Method() {} function Plus() { this.call = function(args) { var result = args[0]; var i = 1; while (args[i] != null) { result += args[i]; i++; } return result; } } Plus.prototype = new Native_Method(); function Minus() { this.call = function(args) { var result = args[0]; var i = 1; while (args[i] != null) { result -= args[i]; i++; } return result; } } Minus.prototype = new Native_Method(); function Multiply() { this.call = function(args) { var result = 1; var i = 0; while (args[i] != null) { result *= args[i]; i++; } return result; } } Multiply.prototype = new Native_Method(); function Cons() { this.call = function(args) { return new Pair(args[0], args[1]); } } Cons.prototype = new Native_Method(); function Is_Pair() { this.call = function(args) { return is_pair(args[0]); } } Is_Pair.prototype = new Native_Method(); function Is_Number() { this.call = function(args) { return is_pair(args[0]); } } Is_Pair.prototype = new Native_Method(); function Is_Bool() { this.call = function(args) { return is_boolean(args[0]); } } Is_Bool.prototype = new Native_Method(); function Car() { this.call = function(args) { return car(args[0]); } } Car.prototype = new Native_Method(); function Cdr() { this.call = function(args) { return cdr(args[0]); } } Cdr.prototype = new Native_Method(); keys0 = new Array(); keys0.push(new Symbol("+")); keys0.push(new Symbol("-")); keys0.push(new Symbol("*")); keys0.push(new Symbol("lambda")); keys0.push(new Symbol("define")); keys0.push(new Symbol("quote")); keys0.push(new Symbol("if")); keys0.push(new Symbol("pair?")); keys0.push(new Symbol("number?")); keys0.push(new Symbol("boolean?")); keys0.push(new Symbol("cons")); keys0.push(new Symbol("car")); keys0.push(new Symbol("cdr")); values0 = new Array(); values0.push(new Plus()); values0.push(new Minus()); values0.push(new Multiply()); values0.push(new Lambda()); values0.push(new Define()); values0.push(new Quote()); values0.push(new If()); values0.push(new Is_Pair()); values0.push(new Is_Number()); values0.push(new Is_Bool()); values0.push(new Cons()); values0.push(new Car()); values0.push(new Cdr()); env0 = new Environment(null,keys0); env0.bindVals(values0);