From f7c8c3effe43f0f02a1696f37cc50d06599fe52d Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 9 Dec 2017 03:25:15 -0800 Subject: 4157 --- html/same-fringe.mu.html | 62 ++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 31 deletions(-) (limited to 'html/same-fringe.mu.html') diff --git a/html/same-fringe.mu.html b/html/same-fringe.mu.html index 329f4393..bc49aae9 100644 --- a/html/same-fringe.mu.html +++ b/html/same-fringe.mu.html @@ -3,7 +3,7 @@ Mu - same-fringe.mu - + @@ -15,16 +15,16 @@ body { font-size: 12pt; font-family: monospace; color: #aaaaaa; background-color a { color:#eeeeee; text-decoration: none; } a:hover { text-decoration: underline; } * { font-size: 12pt; font-size: 1em; } -.muRecipe { color: #ff8700; } -.Special { color: #c00000; } .Conceal { color: #4e4e4e; } +.muData { color: #ffff00; } +.LineNr { color: #444444; } .Delimiter { color: #800080; } .Comment { color: #9090ff; } .Comment a { color:#0000ee; text-decoration:underline; } .Constant { color: #00a0a0; } -.LineNr { color: #444444; } +.Special { color: #c00000; } .muControl { color: #c0a020; } -.muData { color: #ffff00; } +.muRecipe { color: #ff8700; } --> @@ -59,40 +59,40 @@ if ('onhashchange' in window) {
- 1 # Another example of continuations: the 'same fringe' problem
- 2 #   http://wiki.c2.com/?SameFringeProblem
+ 1 # The 'same fringe' problem: http://wiki.c2.com/?SameFringeProblem
+ 2 # Example program demonstrating coroutines using Mu's delimited continuations.
  3 #
  4 # Expected output:
  5 #   1
  6 # (i.e. that the two given trees x and y have the same leaves, in the same
  7 # order from left to right)
  8 
- 9 container tree:_elem [
+ 9 container tree:_elem [
 10   val:_elem
-11   left:&:tree:_elem
-12   right:&:tree:_elem
+11   left:&:tree:_elem
+12   right:&:tree:_elem
 13 ]
 14 
-15 def main [
+15 def main [
 16   local-scope
 17   # x: ((a b) c)
 18   # y: (a (b c))
-19   a:&:tree:num <- new-tree 3
-20   b:&:tree:num <- new-tree 4
-21   c:&:tree:num <- new-tree 5
-22   x1:&:tree:num <- new-tree a, b
-23   x:&:tree:num <- new-tree x1, c
-24   y1:&:tree:num <- new-tree b, c
-25   y:&:tree:num <- new-tree a, y1
-26   result:bool <- same-fringe x, y
+19   a:&:tree:num <- new-tree 3
+20   b:&:tree:num <- new-tree 4
+21   c:&:tree:num <- new-tree 5
+22   x1:&:tree:num <- new-tree a, b
+23   x:&:tree:num <- new-tree x1, c
+24   y1:&:tree:num <- new-tree b, c
+25   y:&:tree:num <- new-tree a, y1
+26   result:bool <- same-fringe x, y
 27   $print result 10/newline
 28 ]
 29 
-30 def same-fringe a:&:tree:_elem, b:&:tree:_elem -> result:bool [
+30 def same-fringe a:&:tree:_elem, b:&:tree:_elem -> result:bool [
 31   local-scope
 32   load-inputs
-33   k1:continuation <- call-with-continuation-mark process, a
-34   k2:continuation <- call-with-continuation-mark process, b
+33   k1:continuation <- call-with-continuation-mark process, a
+34   k2:continuation <- call-with-continuation-mark process, b
 35   {
 36   ¦ k1, x:_elem, a-done?:bool <- call k1
 37   ¦ k2, y:_elem, b-done?:bool <- call k2
@@ -106,25 +106,25 @@ if ('onhashchange' in window) {
 45 ]
 46 
 47 # harness around traversal
-48 def process t:&:tree:_elem [
+48 def process t:&:tree:_elem [
 49   local-scope
 50   load-inputs
 51   return-continuation-until-mark  # initial
-52   traverse t
+52   traverse t
 53   zero-val:&:_elem <- new _elem:type
 54   return-continuation-until-mark *zero-val, 1/done  # final
 55   assert 0/false, [continuation called past done]
 56 ]
 57 
 58 # core traversal
-59 def traverse t:&:tree:_elem [
+59 def traverse t:&:tree:_elem [
 60   local-scope
 61   load-inputs
 62   return-unless t
-63   l:&:tree:_elem <- get *t, left:offset
-64   traverse l
-65   r:&:tree:_elem <- get *t, right:offset
-66   traverse r
+63   l:&:tree:_elem <- get *t, left:offset
+64   traverse l
+65   r:&:tree:_elem <- get *t, right:offset
+66   traverse r
 67   return-if l
 68   return-if r
 69   # leaf
@@ -134,14 +134,14 @@ if ('onhashchange' in window) {
 73 
 74 # details
 75 
-76 def new-tree x:_elem -> result:&:tree:_elem [
+76 def new-tree x:_elem -> result:&:tree:_elem [
 77   local-scope
 78   load-inputs
 79   result <- new {(tree _elem): type}
 80   put *result, val:offset, x
 81 ]
 82 
-83 def new-tree l:&:tree:_elem, r:&:tree:_elem -> result:&:tree:_elem [
+83 def new-tree l:&:tree:_elem, r:&:tree:_elem -> result:&:tree:_elem [
 84   local-scope
 85   load-inputs
 86   result <- new {(tree _elem): type}
-- 
cgit 1.4.1-2-gfad0