summaryrefslogtreecommitdiff
path: root/appl/lib/lists.b
diff options
context:
space:
mode:
authorforsyth <forsyth@vitanuova.com>2011-04-07 10:04:31 +0100
committerforsyth <forsyth@vitanuova.com>2011-04-07 10:04:31 +0100
commit09fa9b42130335ddb8876b9be05f780093519864 (patch)
tree502762ed084531ebd86c1aff3bfb112d36f221dc /appl/lib/lists.b
parentc2ef9233feb49e4dc90f4f58fc499eb2c607bf7d (diff)
20110407-1004
Diffstat (limited to 'appl/lib/lists.b')
-rw-r--r--appl/lib/lists.b34
1 files changed, 21 insertions, 13 deletions
diff --git a/appl/lib/lists.b b/appl/lib/lists.b
index 52e007bb..31d26ddb 100644
--- a/appl/lib/lists.b
+++ b/appl/lib/lists.b
@@ -87,22 +87,30 @@ last[T](l: list of T): T
return hd l;
}
-# delete the first instance of x in l
-delete[T](x: T, al: list of T): list of T
+# find instance of x in l, return tail of l from x
+find[T](x: T, l: list of T): list of T
for { T => eq: fn(a, b: T): int; }
{
- for(l := al; l != nil; l = tl l){
- if(T.eq(x, hd l)){
- o: list of T;
- for(; al != l; al = tl al)
- o = hd al :: o;
- l = tl l;
- for(; o != nil; o = tl o)
- l = hd o :: l;
+ for(; l != nil; l = tl l)
+ if(T.eq(x, hd l))
return l;
- }
- }
- return al;
+ return nil;
+}
+
+# delete the first instance of x in l
+delete[T](x: T, l: list of T): list of T
+ for { T => eq: fn(a, b: T): int; }
+{
+ loc := find(x, l);
+ if(loc == nil)
+ return l;
+ o: list of T;
+ for(; l != loc; l = tl l)
+ o = hd l :: o;
+ l = tl loc;
+ for(; o != nil; o = tl o)
+ l = hd o :: l;
+ return l;
}
pair[T1, T2](l1: list of T1, l2: list of T2): list of (T1, T2)