about summary refs log tree commit diff stats
path: root/080display.cc
Commit message (Expand)AuthorAgeFilesLines
* 3306 - better error messages when mixing up screen/consoleKartik K. Agaram2016-09-081-0/+38
* 3271Kartik K. Agaram2016-08-281-1/+2
* 3259Kartik K. Agaram2016-08-261-5/+5
* 3164Kartik K. Agaram2016-08-091-0/+1
* 3163Kartik K. Agaram2016-08-091-0/+13
* 3162Kartik K. Agaram2016-08-091-3/+5
* 3120Kartik K. Agaram2016-07-211-2/+2
* 2990Kartik K. Agaram2016-05-201-7/+7
* 2803Kartik K. Agaram2016-03-211-2/+2
* 2773 - switch to 'int'Kartik K. Agaram2016-03-131-10/+10
* 2712Kartik K. Agaram2016-02-261-9/+9
* 2685Kartik K. Agaram2016-02-191-2/+2
* 2553 - keep failed specializations from generating spurious errorsKartik K. Agaram2015-12-281-1/+0
* three bugs fixedKartik K. Agaram2015-12-151-1/+5
* 2430 - make room for more transformsKartik K. Agaram2015-11-131-0/+498
revious revision' href='/akkartik/mu/blame/continuation5.mu?h=hlt&id=1cd833619e355c70d5d96a208cd67ba3a3ccb937'>^
3b776ac3 ^











4a48bedc ^
3b776ac3 ^

01ce563d ^
3b776ac3 ^



5059f32d ^
3b776ac3 ^

5059f32d ^
dd660682 ^
3b776ac3 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
                                                                            
         


                                                                              
 




                                              



                  


             
                           


                
                                                                                              











                                                                     
             

                 
                          



                  
                                                                          

        
                                                    
                                                                           
 
# Example program showing that a 'paused' continuation can be 'resumed' with
# inputs.
#
# Print out a list of numbers, first adding 0 to the first, 1 to the second, 2
# to the third, and so on.
#
# To run:
#   $ git clone https://github.com/akkartik/mu
#   $ cd mu
#   $ ./mu continuation5.mu
#
# Expected output:
#   1
#   3
#   5

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

def create-yielder l:&:list:num -> n:num, done?:bool [
  local-scope
  load-inputs
  a:num <- copy 0
  {
    done? <- equal l, null
    break-if done?
    n <- first l
    l <- rest l
    n <- add n, a
    a <- return-continuation-until-mark 100/mark, n, done?  # pause/resume
    loop
  }
  return-continuation-until-mark 100/mark, -1, done?
  assert false, [called too many times, ran out of continuations to return]
]