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