Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Env.toJs can be shallow (don't convert parents) Env.fromJsObject to c…

…reate an env squimifying a js object
  • Loading branch information...
commit 9ef9de9889d70da445d21864339cf3ff47b914c4 1 parent 5296078
Mariano Guerra authored
Showing with 28 additions and 5 deletions.
  1. +28 −5 src/squim.types.js
33 src/squim.types.js
View
@@ -406,19 +406,42 @@
Env.prototype.equal_p = Env.prototype.eq_p;
- Env.prototype.toJs = function () {
- var i, parents = [];
+ // if shallow is true then don't convert parents toJs
+ Env.prototype.toJs = function (shallow) {
+ var i, parents = [], key, bindings = {};
- for (i = 0; i < this.parents.length; i += 1) {
- parents.push(this.parents[i].toJs());
+ for (key in this.bindings) {
+ bindings[key] = this.bindings[key].toJs();
+ }
+
+ if (!shallow) {
+ for (i = 0; i < this.parents.length; i += 1) {
+ parents.push(this.parents[i].toJs());
+ }
}
return {
- "bindings": this.bindings,
+ "bindings": bindings,
"parents": parents
};
};
+ // convert js object *bindings* to a js object that contains all it's
+ // attributes as squim objects to be used as a bindings object for an environment
+ // return a new Env with *bindings* as bindings of the environment
+ Env.fromJsObject = function (bindings, parents) {
+ var key, squimBindings = {};
+
+ for (key in bindings) {
+ if (bindings.hasOwnProperty(key)) {
+ squimBindings[key] = obj.squimify(bindings[key]);
+ }
+ }
+
+ return new Env(bindings, parent);
+ };
+
+
function Applicative(operative) {
this.operative = operative;
}
Please sign in to comment.
Something went wrong with that request. Please try again.