1 # Example program showing that a 'paused' continuation can be 'resumed' with
4 # Print out a list of numbers, first adding 0 to the first, 1 to the second, 2
5 # to the third, and so on.
8 # $ git clone https://github.com/akkartik/mu
10 # $ ./mu continuation5.mu
19 l:&:list:num <- copy null
23 k:continuation, x:num, done?:bool <- call-with-continuation-mark 100/mark, create-yielder, l
28 k, x:num, done?:bool <- call k, a # resume; x = a + next l value
34 def create-yielder l:&:list:num -> n:num, done?:bool [
39 done? <- equal l, null
44 a <- return-continuation-until-mark 100/mark, n, done? # pause/resume
47 return-continuation-until-mark 100/mark, -1, done?
48 assert false, [called too many times, ran out of continuations to return]