1 // Node vs browser behavior
3 if (typeof module
=== 'undefined') {
8 function Env(outer
, binds
, exprs
) {
10 this.outer
= outer
|| null;
13 // Returns a new Env with symbols in binds bound to
14 // corresponding values in exprs
15 // TODO: check types of binds and exprs and compare lengths
16 for (var i
=0; i
<binds
.length
;i
++) {
17 if (binds
[i
].value
=== "&") {
18 // variable length arguments
19 this.data
[binds
[i
+1].value
] = Array
.prototype.slice
.call(exprs
, i
);
22 this.data
[binds
[i
].value
] = exprs
[i
];
28 Env
.prototype.find = function (key
) {
29 if (key
in this.data
) { return this; }
30 else if (this.outer
) { return this.outer
.find(key
); }
33 Env
.prototype.set = function(key
, value
) { this.data
[key
] = value
; return value
; },
34 Env
.prototype.get = function(key
) {
35 var env
= this.find(key
);
36 if (!env
) { throw new Error("'" + key
+ "' not found"); }
40 exports
.Env
= env
.Env
= Env
;