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/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 100/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-inputs
32   return-continuation-until-mark 100/mark
33   done? <- equal l, 0/nil
34   return-if done?, 0/false
35   n <- first l
36   l <- rest l
37 ]