From ef7d834fdd826977cd8d43253052a7b8e1c5aa72 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 25 Nov 2017 10:17:23 -0800 Subject: 4133 --- html/continuation2.mu.html | 63 +++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 29 deletions(-) (limited to 'html/continuation2.mu.html') diff --git a/html/continuation2.mu.html b/html/continuation2.mu.html index 46e33c2f..95756684 100644 --- a/html/continuation2.mu.html +++ b/html/continuation2.mu.html @@ -61,35 +61,40 @@ if ('onhashchange' in window) { 1 # Example program showing that a 'paused' continuation can be 'resumed' 2 # multiple times from the same point (but with changes to data). 3 # - 4 # Expected output: - 5 # 1 - 6 # 2 - 7 # 3 - 8 - 9 def main [ -10 local-scope -11 l:&:list:num <- copy 0 -12 l <- push 3, l -13 l <- push 2, l -14 l <- push 1, l -15 k:continuation <- call-with-continuation-mark create-yielder, l -16 { -17 ¦ x:num, done?:bool <- call k -18 ¦ break-if done? -19 ¦ $print x 10/newline -20 ¦ loop -21 } -22 ] -23 -24 def create-yielder l:&:list:num -> n:num, done?:bool [ -25 local-scope -26 load-ingredients -27 return-continuation-until-mark -28 done? <- equal l, 0 -29 return-if done?, 0 -30 n <- first l -31 l <- rest l -32 ] + 4 # To run: + 5 # $ git clone https://github.com/akkartik/mu + 6 # $ cd mu + 7 # $ ./mu continuation2.mu + 8 # + 9 # Expected output: +10 # 1 +11 # 2 +12 # 3 +13 +14 def main [ +15 local-scope +16 l:&:list:num <- copy 0 +17 l <- push 3, l +18 l <- push 2, l +19 l <- push 1, l +20 k:continuation <- call-with-continuation-mark create-yielder, l +21 { +22 ¦ x:num, done?:bool <- call k +23 ¦ break-if done? +24 ¦ $print x 10/newline +25 ¦ loop +26 } +27 ] +28 +29 def create-yielder l:&:list:num -> n:num, done?:bool [ +30 local-scope +31 load-ingredients +32 return-continuation-until-mark +33 done? <- equal l, 0 +34 return-if done?, 0 +35 n <- first l +36 l <- rest l +37 ] -- cgit 1.4.1-2-gfad0