about summary refs log blame commit diff stats
path: root/cpp/.traces/loop_label
blob: b0c4c2a8a21e9befe822eec6ab361aeea8cc90f8 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
                       

                                                                                   

                       

                                                                                   


                          
er  Kartik K. Agaram <vc@akkartik.com>  2017-11-03 01:49:36 -0700

4103 - continuations no longer cause memory corruption' href='/akkartik/mu/commit/continuation2.mu?h=hlt&id=a3195d440d2f0e99400db78e5a4386691c94a9a0'>a3195d44 ^









1
2
3
4
5
6
7
8


                                                                       




                                              



                  


             
                           


                
                                                                           









                                                      
             
                                         

                          


              
# Example program showing that a 'paused' continuation can be 'resumed'
# multiple times from the same point (but with changes to data).
#
# To run:
#   $ git clone https://github.com/akkartik/mu
#   $ cd mu
#   $ ./mu continuation2.mu
#
# Expected output:
#   1
#   2
#   3

def main [
  local-scope
  l:&:list:num <- copy null
  l <- push 3, l
  l <- push 2, l
  l <- push 1, l
  k:continuation <- call-with-continuation-mark 100/mark, create-yielder, l
  {
    x:num, done?:bool <- call k
    break-if done?
    $print x 10/newline
    loop
  }
]

def create-yielder l:&:list:num -> n:num, done?:bool [
  local-scope
  load-inputs
  return-continuation-until-mark 100/mark
  done? <- equal l, null
  return-if done?, 0/dummy
  n <- first l
  l <- rest l
]