From 6c52e24e2996a77aa6297b26159003d503aef8a0 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 18 Apr 2017 11:33:33 -0700 Subject: 3830 - crosslink shape-shifting containers in html --- html/064list.mu.html | 146 +++++++++++++++++++++++++-------------------------- 1 file changed, 73 insertions(+), 73 deletions(-) (limited to 'html/064list.mu.html') diff --git a/html/064list.mu.html b/html/064list.mu.html index e1f93300..3f604a5e 100644 --- a/html/064list.mu.html +++ b/html/064list.mu.html @@ -65,26 +65,26 @@ if ('onhashchange' in window) { 3 # The objects must be of the same type. If you want to store multiple types in 4 # a single list, use an exclusive-container. 5 - 6 container list:_elem [ + 6 container list:_elem [ 7 value:_elem - 8 next:&:list:_elem + 8 next:&:list:_elem 9 ] 10 - 11 def push x:_elem, l:&:list:_elem -> l:&:list:_elem [ + 11 def push x:_elem, l:&:list:_elem -> l:&:list:_elem [ 12 local-scope 13 load-ingredients - 14 result:&:list:_elem <- new {(list _elem): type} + 14 result:&:list:_elem <- new {(list _elem): type} 15 *result <- merge x, l 16 return result 17 ] 18 - 19 def first in:&:list:_elem -> result:_elem [ + 19 def first in:&:list:_elem -> result:_elem [ 20 local-scope 21 load-ingredients 22 result <- get *in, value:offset 23 ] 24 - 25 def rest in:&:list:_elem -> result:&:list:_elem/contained-in:in [ + 25 def rest in:&:list:_elem -> result:&:list:_elem/contained-in:in [ 26 local-scope 27 load-ingredients 28 result <- get *in, next:offset @@ -93,7 +93,7 @@ if ('onhashchange' in window) { 31 scenario list-handling [ 32 run [ 33 ¦ local-scope - 34 ¦ x:&:list:num <- push 3, 0 + 34 ¦ x:&:list:num <- push 3, 0 35 ¦ x <- push 4, x 36 ¦ x <- push 5, x 37 ¦ 10:num/raw <- first x @@ -101,7 +101,7 @@ if ('onhashchange' in window) { 39 ¦ 11:num/raw <- first x 40 ¦ x <- rest x 41 ¦ 12:num/raw <- first x - 42 ¦ 20:&:list:num/raw <- rest x + 42 ¦ 20:&:list:num/raw <- rest x 43 ] 44 memory-should-contain [ 45 ¦ 10 <- 5 @@ -111,7 +111,7 @@ if ('onhashchange' in window) { 49 ] 50 ] 51 - 52 def length l:&:list:_elem -> result:num [ + 52 def length l:&:list:_elem -> result:num [ 53 local-scope 54 load-ingredients 55 result <- copy 0 @@ -124,26 +124,26 @@ if ('onhashchange' in window) { 62 ] 63 64 # insert 'x' after 'in' - 65 def insert x:_elem, in:&:list:_elem -> in:&:list:_elem [ + 65 def insert x:_elem, in:&:list:_elem -> in:&:list:_elem [ 66 local-scope 67 load-ingredients - 68 new-node:&:list:_elem <- new {(list _elem): type} + 68 new-node:&:list:_elem <- new {(list _elem): type} 69 *new-node <- put *new-node, value:offset, x - 70 next-node:&:list:_elem <- get *in, next:offset + 70 next-node:&:list:_elem <- get *in, next:offset 71 *in <- put *in, next:offset, new-node 72 *new-node <- put *new-node, next:offset, next-node 73 ] 74 75 scenario inserting-into-list [ 76 local-scope - 77 list:&:list:char <- push 3, 0 - 78 list <- push 4, list - 79 list <- push 5, list + 77 list:&:list:char <- push 3, 0 + 78 list <- push 4, list + 79 list <- push 5, list 80 run [ - 81 ¦ list2:&:list:char <- rest list # inside list + 81 ¦ list2:&:list:char <- rest list # inside list 82 ¦ list2 <- insert 6, list2 83 ¦ # check structure - 84 ¦ list2 <- copy list + 84 ¦ list2 <- copy list 85 ¦ 10:char/raw <- first list2 86 ¦ list2 <- rest list2 87 ¦ 11:char/raw <- first list2 @@ -162,15 +162,15 @@ if ('onhashchange' in window) { 100 101 scenario inserting-at-end-of-list [ 102 local-scope -103 list:&:list:char <- push 3, 0 -104 list <- push 4, list -105 list <- push 5, list +103 list:&:list:char <- push 3, 0 +104 list <- push 4, list +105 list <- push 5, list 106 run [ -107 ¦ list2:&:list:char <- rest list # inside list +107 ¦ list2:&:list:char <- rest list # inside list 108 ¦ list2 <- rest list2 # now at end of list 109 ¦ list2 <- insert 6, list2 110 ¦ # check structure like before -111 ¦ list2 <- copy list +111 ¦ list2 <- copy list 112 ¦ 10:char/raw <- first list2 113 ¦ list2 <- rest list2 114 ¦ 11:char/raw <- first list2 @@ -189,13 +189,13 @@ if ('onhashchange' in window) { 127 128 scenario inserting-after-start-of-list [ 129 local-scope -130 list:&:list:char <- push 3, 0 -131 list <- push 4, list -132 list <- push 5, list +130 list:&:list:char <- push 3, 0 +131 list <- push 4, list +132 list <- push 5, list 133 run [ -134 ¦ list <- insert 6, list +134 ¦ list <- insert 6, list 135 ¦ # check structure like before -136 ¦ list2:&:list:char <- copy list +136 ¦ list2:&:list:char <- copy list 137 ¦ 10:char/raw <- first list2 138 ¦ list2 <- rest list2 139 ¦ 11:char/raw <- first list2 @@ -216,20 +216,20 @@ if ('onhashchange' in window) { 154 # 155 # Returns null if and only if list is empty. Beware: in that case any other 156 # pointers to the head are now invalid. -157 def remove x:&:list:_elem/contained-in:in, in:&:list:_elem -> in:&:list:_elem [ +157 def remove x:&:list:_elem/contained-in:in, in:&:list:_elem -> in:&:list:_elem [ 158 local-scope 159 load-ingredients 160 # if 'x' is null, return 161 return-unless x -162 next-node:&:list:_elem <- rest x +162 next-node:&:list:_elem <- rest x 163 # clear next pointer of 'x' 164 *x <- put *x, next:offset, 0 165 # if 'x' is at the head of 'in', return the new head 166 at-head?:bool <- equal x, in 167 return-if at-head?, next-node 168 # compute prev-node -169 prev-node:&:list:_elem <- copy in -170 curr:&:list:_elem <- rest prev-node +169 prev-node:&:list:_elem <- copy in +170 curr:&:list:_elem <- rest prev-node 171 { 172 ¦ return-unless curr 173 ¦ found?:bool <- equal curr, x @@ -243,19 +243,19 @@ if ('onhashchange' in window) { 181 182 scenario removing-from-list [ 183 local-scope -184 list:&:list:char <- push 3, 0 -185 list <- push 4, list -186 list <- push 5, list +184 list:&:list:char <- push 3, 0 +185 list <- push 4, list +186 list <- push 5, list 187 run [ -188 ¦ list2:&:list:char <- rest list # second element -189 ¦ list <- remove list2, list +188 ¦ list2:&:list:char <- rest list # second element +189 ¦ list <- remove list2, list 190 ¦ 10:bool/raw <- equal list2, 0 191 ¦ # check structure like before -192 ¦ list2 <- copy list +192 ¦ list2 <- copy list 193 ¦ 11:char/raw <- first list2 194 ¦ list2 <- rest list2 195 ¦ 12:char/raw <- first list2 -196 ¦ 20:&:list:char/raw <- rest list2 +196 ¦ 20:&:list:char/raw <- rest list2 197 ] 198 memory-should-contain [ 199 ¦ 10 <- 0 # remove returned non-null @@ -267,17 +267,17 @@ if ('onhashchange' in window) { 205 206 scenario removing-from-start-of-list [ 207 local-scope -208 list:&:list:char <- push 3, 0 -209 list <- push 4, list -210 list <- push 5, list +208 list:&:list:char <- push 3, 0 +209 list <- push 4, list +210 list <- push 5, list 211 run [ -212 ¦ list <- remove list, list +212 ¦ list <- remove list, list 213 ¦ # check structure like before -214 ¦ list2:&:list:char <- copy list +214 ¦ list2:&:list:char <- copy list 215 ¦ 10:char/raw <- first list2 216 ¦ list2 <- rest list2 217 ¦ 11:char/raw <- first list2 -218 ¦ 20:&:list:char/raw <- rest list2 +218 ¦ 20:&:list:char/raw <- rest list2 219 ] 220 memory-should-contain [ 221 ¦ 10 <- 4 # scanning next, skipping deleted element @@ -288,21 +288,21 @@ if ('onhashchange' in window) { 226 227 scenario removing-from-end-of-list [ 228 local-scope -229 list:&:list:char <- push 3, 0 -230 list <- push 4, list -231 list <- push 5, list +229 list:&:list:char <- push 3, 0 +230 list <- push 4, list +231 list <- push 5, list 232 run [ 233 ¦ # delete last element -234 ¦ list2:&:list:char <- rest list +234 ¦ list2:&:list:char <- rest list 235 ¦ list2 <- rest list2 -236 ¦ list <- remove list2, list +236 ¦ list <- remove list2, list 237 ¦ 10:bool/raw <- equal list2, 0 238 ¦ # check structure like before -239 ¦ list2 <- copy list +239 ¦ list2 <- copy list 240 ¦ 11:char/raw <- first list2 241 ¦ list2 <- rest list2 242 ¦ 12:char/raw <- first list2 -243 ¦ 20:&:list:char/raw <- rest list2 +243 ¦ 20:&:list:char/raw <- rest list2 244 ] 245 memory-should-contain [ 246 ¦ 10 <- 0 # remove returned non-null @@ -314,10 +314,10 @@ if ('onhashchange' in window) { 252 253 scenario removing-from-singleton-list [ 254 local-scope -255 list:&:list:char <- push 3, 0 +255 list:&:list:char <- push 3, 0 256 run [ -257 ¦ list <- remove list, list -258 ¦ 1:num/raw <- copy list +257 ¦ list <- remove list, list +258 ¦ 1:num/raw <- copy list 259 ] 260 memory-should-contain [ 261 ¦ 1 <- 0 # back to an empty list @@ -326,50 +326,50 @@ if ('onhashchange' in window) { 264 265 # reverse the elements of a list 266 # (contributed by Caleb Couch) -267 def reverse list:&:list:_elem temp:&:list:_elem/contained-in:result -> result:&:list:_elem [ +267 def reverse list:&:list:_elem temp:&:list:_elem/contained-in:result -> result:&:list:_elem [ 268 local-scope 269 load-ingredients -270 return-unless list, temp -271 object:_elem <- first, list -272 list <- rest list +270 return-unless list, temp +271 object:_elem <- first, list +272 list <- rest list 273 temp <- push object, temp -274 result <- reverse list, temp +274 result <- reverse list, temp 275 ] 276 277 scenario reverse-list [ 278 local-scope -279 list:&:list:number <- push 1, 0 -280 list <- push 2, list -281 list <- push 3, list +279 list:&:list:number <- push 1, 0 +280 list <- push 2, list +281 list <- push 3, list 282 run [ -283 ¦ stash [list:], list -284 ¦ list <- reverse list -285 ¦ stash [reversed:], list +283 ¦ stash [list:], list +284 ¦ list <- reverse list +285 ¦ stash [reversed:], list 286 ] 287 trace-should-contain [ -288 ¦ app: list: 3 -> 2 -> 1 +288 ¦ app: list: 3 -> 2 -> 1 289 ¦ app: reversed: 1 -> 2 -> 3 290 ] 291 ] 292 -293 def to-text in:&:list:_elem -> result:text [ +293 def to-text in:&:list:_elem -> result:text [ 294 local-scope 295 load-ingredients -296 buf:&:buffer:char <- new-buffer 80 +296 buf:&:buffer:char <- new-buffer 80 297 buf <- to-buffer in, buf 298 result <- buffer-to-array buf 299 ] 300 301 # variant of 'to-text' which stops printing after a few elements (and so is robust to cycles) -302 def to-text-line in:&:list:_elem -> result:text [ +302 def to-text-line in:&:list:_elem -> result:text [ 303 local-scope 304 load-ingredients -305 buf:&:buffer:char <- new-buffer 80 +305 buf:&:buffer:char <- new-buffer 80 306 buf <- to-buffer in, buf, 6 # max elements to display 307 result <- buffer-to-array buf 308 ] 309 -310 def to-buffer in:&:list:_elem, buf:&:buffer:char -> buf:&:buffer:char [ +310 def to-buffer in:&:list:_elem, buf:&:buffer:char -> buf:&:buffer:char [ 311 local-scope 312 load-ingredients 313 { @@ -381,7 +381,7 @@ if ('onhashchange' in window) { 319 val:_elem <- get *in, value:offset 320 buf <- append buf, val 321 # now prepare next -322 next:&:list:_elem <- rest in +322 next:&:list:_elem <- rest in 323 nextn:num <- copy next 324 return-unless next 325 buf <- append buf, [ -> ] @@ -406,7 +406,7 @@ if ('onhashchange' in window) { 344 345 scenario stash-empty-list [ 346 local-scope -347 x:&:list:num <- copy 0 +347 x:&:list:num <- copy 0 348 run [ 349 ¦ stash x 350 ] -- cgit 1.4.1-2-gfad0