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 # To run:
 5 #   $ git clone https://github.com/akkartik/mu1
 6 #   $ cd mu1
 7 #   $ git checkout 4a48bedcd1  # state as of this writing; later versions may be incompatible
 8 #   $ ./mu continuation2.mu
 9 #
10 # Expected output:
11 #   1
12 #   2
13 #   3
14 
15 def main [
16   local-scope
17   l:&:list:num <- copy 0
18   l <- push 3, l
19   l <- push 2, l
20   l <- push 1, l
21   k:continuation <- call-with-continuation-mark create-yielder, l
22   {
23   ¦ x:num, done?:bool <- call k
24   ¦ break-if done?
25   ¦ $print x 10/newline
26   ¦ loop
27   }
28 ]
29 
30 def create-yielder l:&:list:num -> n:num, done?:bool [
31   local-scope
32   load-inputs
33   return-continuation-until-mark
34   done? <- equal l, 0
35   return-if done?, 0
36   n <- first l
37   l <- rest l
38 ]