summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/hosting/server/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'sca-cpp/trunk/hosting/server/util.py')
-rw-r--r--sca-cpp/trunk/hosting/server/util.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/sca-cpp/trunk/hosting/server/util.py b/sca-cpp/trunk/hosting/server/util.py
index 24467fd2cb..791951a71c 100644
--- a/sca-cpp/trunk/hosting/server/util.py
+++ b/sca-cpp/trunk/hosting/server/util.py
@@ -60,7 +60,7 @@ def reverse(l):
def isNil(l):
if isinstance(l, streampair):
return l.isNil()
- return l == ()
+ return l is None or l == ()
def isSymbol(v):
return isinstance(v, basestring) and v[0:1] == "'"
@@ -131,12 +131,25 @@ def cons_stream(car, cdr):
# Scheme-like associations
def assoc(k, l):
if l == ():
- return None
-
+ return ()
if k == car(car(l)):
return car(l)
return assoc(k, cdr(l))
+def delAssoc(k, l):
+ if l == ():
+ return ()
+ if k == car(car(l)):
+ return delAssoc(k, cdr(l))
+ return cons(car(l), delAssoc(k, cdr(l)))
+
+def substAssoc(k, n, l, a = False):
+ if l == ():
+ return (n,) if a else ()
+ if k == car(car(l)):
+ return cons(n, substAssoc(k, n, cdr(l), False))
+ return cons(car(l), substAssoc(k, n, cdr(l), a))
+
# Currying / partial function application
def curry(f, *args):
return lambda *a: f(*(args + a))