about summary refs log tree commit diff stats
path: root/continuation4.mu
blob: adbb70d9412047ddcb3351ca45a2a64a5d80525b (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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Example program showing 'return-continuation-until-mark' return other values
# alongside continuations.
#
# Print out a given list of numbers.
#
# Expected output:
#   1
#   2
#   3

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

def create-yielder l:&:list:num -> n:num, done?:bool [
  local-scope
  load-ingredients
  {
    done? <- equal l, 0
    break-if done?
    n <- first l
    l <- rest l
    return-continuation-until-mark n, done?
    loop
  }
  # A function that returns continuations shouldn't get the opportunity to
  # return. Calling functions should stop calling its continuation after this
  # point.
  return-continuation-until-mark -1, done?
  assert 0/false, [called too many times, ran out of continuations to return]
]
i">&nbsp;make&nbsp;sure&nbsp;the&nbsp;import-line&nbsp;stays&nbsp;intact&nbsp;and&nbsp;the&nbsp;type<br> of&nbsp;the&nbsp;values&nbsp;stay&nbsp;the&nbsp;same.</tt></p> <p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#aa55cc"> <td colspan=3 valign=bottom>&nbsp;<br> <font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr> <tr><td bgcolor="#aa55cc"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td> <td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="ranger.colorschemes.html">ranger.colorschemes</a><br> </td><td width="25%" valign=top><a href="ranger.gui.color.html">ranger.gui.color</a><br> </td><td width="25%" valign=top><a href="re.html">re</a><br> </td><td width="25%" valign=top></td></tr></table></td></tr></table><p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#55aa55"> <td colspan=3 valign=bottom>&nbsp;<br> <font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr> <tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td> <td width="100%"><strong>autosave_bookmarks</strong> = True<br> <strong>collapse_preview</strong> = True<br> <strong>colorscheme</strong> = 'default'<br> <strong>colorscheme_overlay</strong> = None<br> <strong>draw_bookmark_borders</strong> = True<br> <strong>draw_borders</strong> = False<br> <strong>flushinput</strong> = True<br> <strong>hidden_filter</strong> = &lt;_sre.SRE_Pattern object&gt;<br> <strong>max_filesize_for_preview</strong> = 307200<br> <strong>max_history_size</strong> = 20<br> <strong>preview_directories</strong> = True<br> <strong>preview_files</strong> = True<br> <strong>save_console_history</strong> = True<br> <strong>scroll_offset</strong> = 2<br> <strong>shorten_title</strong> = 3<br> <strong>show_cursor</strong> = False<br> <strong>show_hidden</strong> = False<br> <strong>sort</strong> = 'basename'<br> <strong>sort_case_insensitive</strong> = False<br> <strong>sort_directories_first</strong> = True<br> <strong>sort_reverse</strong> = False<br> <strong>update_title</strong> = True</td></tr></table> </body></html>