summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/modules/js/htdocs/util.js
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2011-02-02 10:04:44 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2011-02-02 10:04:44 +0000
commitf07b324e6f0f2edb71c4dc1d6b63e8a3743c48a6 (patch)
treef9c59fa81f2d56b87066fc54b9b553ac4c43fd35 /sca-cpp/trunk/modules/js/htdocs/util.js
parentd8df0d6da27ac9c4c61863bc7700db7a871ae8d4 (diff)
Support for wiring and unwiring references.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1066399 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk/modules/js/htdocs/util.js')
-rw-r--r--sca-cpp/trunk/modules/js/htdocs/util.js80
1 files changed, 18 insertions, 62 deletions
diff --git a/sca-cpp/trunk/modules/js/htdocs/util.js b/sca-cpp/trunk/modules/js/htdocs/util.js
index 873874c7be..2521b82311 100644
--- a/sca-cpp/trunk/modules/js/htdocs/util.js
+++ b/sca-cpp/trunk/modules/js/htdocs/util.js
@@ -52,10 +52,18 @@ function cddr(l) {
return cdr(cdr(l));
}
+function cdddr(l) {
+ return cdr(cdr(cdr(l)));
+}
+
function caddr(l) {
return car(cddr(l));
}
+function cadddr(l) {
+ return car(cdddr(l));
+}
+
function append(a, b) {
return a.concat(b);
}
@@ -213,16 +221,18 @@ function writeValue(v) {
* Apply a function and memoize its result.
*/
function memo(obj, key, f) {
- if (obj[key])
- return obj[key];
- return obj[key] = f();
+ if (!obj[memo])
+ obj.memo = {};
+ if (obj.memo[key])
+ return obj.memo[key];
+ return obj.memo[key] = f();
}
/**
- * Un-memoize a value.
+ * Un-memoize store results.
*/
-function unmemo(obj, key) {
- obj[key] = null;
+function unmemo(obj) {
+ obj.memo = {};
return true;
}
@@ -276,63 +286,9 @@ function setcdr(a, b) {
* Set the contents of a list.
*/
function setlist(a, b) {
+ if (b == a)
+ return b;
a.length = 0;
return setappend(a, b);
}
-/**
- * Insert a value at a given position in a list.
- */
-function insertn$(v, n, l) {
- function upshift(i) {
- if (i == n)
- return true;
- l[i] = l[i - 1];
- return upshift(i - 1);
- }
-
- upshift(length(l));
- l[n] = v;
- return l;
-}
-
-/**
- * Insert a value at the beginning of a list.
- */
-function insert$(v, l) {
- return insertn$(v, 0, l);
-}
-
-/**
- * Append a list at the end of a list.
- */
-function append$(a, b) {
- if (isNil(b))
- return a;
- a.push(car(b));
- return append$(a, cdr(b));
-}
-
-/**
- * Delete a value from a list.
- */
-function delete$(v, l) {
- function dnshift(i, max) {
- if (i >= max)
- return true;
- l[i] = l[i + 1];
- return dnshift(i + 1, max);
- }
-
- dnshift(n, length(l) - 1);
- l.pop();
- return l;
-}
-
-/**
- * Delete a value at the beginning of a list.
- */
-function delete$(l) {
- return deleten$(l, 0);
-}
-