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