about summary refs log tree commit diff stats
path: root/continuation1.mu
blob: 23e92f8f83fac9a9ca3a4833024d4123276e373d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 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.

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
]