1
2
3
4
5
6
7
8
9
10
11
12 def main [
13 local-scope
14 l:&:list:num <- copy 0
15 l <- push 3, l
16 l <- push 2, l
17 l <- push 1, l
18 k:continuation, x:num, done?:bool <- call-with-continuation-mark create-yielder, l
19 a:num <- copy 1
20 {
21 ¦ break-if done?
22 ¦ $print x 10/newline
23 ¦ k, x:num, done?:bool <- call k, a
24 ¦ a <- add a, 1
25 ¦ loop
26 }
27 ]
28
29 def create-yielder l:&:list:num -> n:num, done?:bool [
30 local-scope
31 load-ingredients
32 a:num <- copy 0
33 {
34 ¦ done? <- equal l, 0
35 ¦ break-if done?
36 ¦ n <- first l
37 ¦ l <- rest l
38 ¦ n <- add n, a
39 ¦ a <- return-continuation-until-mark n, done?
40 ¦ loop
41 }
42 return-continuation-until-mark -1, done?
43 assert 0/false, [called too many times, ran out of continuations to return]
44 ]