1 # example program showing 'return-continuation-until-mark' return other values
 2 # alongside continuations
 3 
 4 def main [
 5   local-scope
 6   l:&:list:num <- copy 0
 7   l <- push 3, l
 8   l <- push 2, l
 9   l <- push 1, l
10   k:continuation, x:num, done?:bool <- call-with-continuation-mark create-yielder, l
11   {
12   ¦ break-if done?
13   ¦ $print x 10/newline
14   ¦ k, x:num, done?:bool <- call k
15   ¦ loop
16   }
17 ]
18 
19 def create-yielder l:&:list:num -> n:num, done?:bool [
20   local-scope
21   load-ingredients
22   {
23   ¦ done? <- equal l, 0
24   ¦ break-if done?
25   ¦ n <- first l
26   ¦ l <- rest l
27   ¦ return-continuation-until-mark n, done?
28   ¦ loop
29   }
30   # A function that returns continuations shouldn't get the opportunity to
31   # return. Calling functions should stop calling its continuation after this
32   # point.
33   return-continuation-until-mark -1, done?
34   assert 0/false, [called too many times, ran out of continuations to return]
35 ]