about summary refs log tree commit diff stats
path: root/065duplex_list.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2017-05-29 01:47:54 -0700
committerKartik K. Agaram <vc@akkartik.com>2017-05-29 02:13:43 -0700
commit284e5576495a946d60603b026bb5e27de356b9fd (patch)
treebf2f1c193e2976c0fe20ef13c6c734cac510b664 /065duplex_list.mu
parentaf4bf7ed2287e051b0d9efdd1918c0812af388e6 (diff)
downloadmu-284e5576495a946d60603b026bb5e27de356b9fd.tar.gz
3894 - comment/uncomment lines in edit app
Diffstat (limited to '065duplex_list.mu')
-rw-r--r--065duplex_list.mu45
1 files changed, 45 insertions, 0 deletions
diff --git a/065duplex_list.mu b/065duplex_list.mu
index 3e43cebc..97541f33 100644
--- a/065duplex_list.mu
+++ b/065duplex_list.mu
@@ -585,6 +585,51 @@ def last in:&:duplex-list:_elem -> result:&:duplex-list:_elem [
   }
 ]
 
+# does a duplex list start with a certain sequence of elements?
+def match x:&:duplex-list:_elem, y:&:@:_elem -> result:bool [
+  local-scope
+  load-ingredients
+  i:num <- copy 0
+  max:num <- length *y
+  {
+    done?:bool <- greater-or-equal i, max
+    break-if done?
+    expected:_elem <- index *y, i
+    return-unless x, 0/no-match
+    curr:_elem <- first x
+    curr-matches?:bool <- equal curr, expected
+    return-unless curr-matches?, 0/no-match
+    x <- next x
+    i <- add i, 1
+    loop
+  }
+  return 1/successful-match
+]
+
+scenario duplex-list-match [
+  local-scope
+  list:&:duplex-list:char <- push 97/a, 0
+  list <- push 98/b, list
+  list <- push 99/c, list
+  list <- push 100/d, list
+  run [
+    10:bool/raw <- match list, []
+    11:bool/raw <- match list, [d]
+    12:bool/raw <- match list, [dc]
+    13:bool/raw <- match list, [dcba]
+    14:bool/raw <- match list, [dd]
+    15:bool/raw <- match list, [dcbax]
+  ]
+  memory-should-contain [
+    10 <- 1  # matches []
+    11 <- 1  # matches [d]
+    12 <- 1  # matches [dc]
+    13 <- 1  # matches [dcba]
+    14 <- 0  # does not match [dd]
+    15 <- 0  # does not match [dcbax]
+  ]
+]
+
 # helper for debugging
 def dump-from x:&:duplex-list:_elem [
   local-scope