about summary refs log blame commit diff stats
path: root/continuation1.mu
blob: 11811c1d970f1db5621f63cb64545493ecfd6871 (plain) (tree)
1
2
3
4
5
6
7
8
                                                                             

                                                                            




                  



















                                                              
# Example program showing that 'return-continuation-until-mark' can 'pause' a
# function call, returning a continuation, and that calling the continuation
# can 'resume' the paused function call.
#
# Expected output:
#   1
#   2
#   3

def main [
  local-scope
  k:continuation <- call-with-continuation-mark create-yielder
  {
    x:num, done?:bool <- call k  # should return 1
    break-if done?
    $print x 10/newline
    loop
  }
]

def create-yielder -> n:num, done?:bool [
  local-scope
  load-ingredients
  n <- copy 0
  return-continuation-until-mark
  done?:bool <- greater-or-equal n, 3
  n <- add n, 1
]