diff options
author | Kartik Agaram <vc@akkartik.com> | 2019-07-27 16:01:55 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2019-07-27 17:47:59 -0700 |
commit | 6e1eeeebfb453fa7c871869c19375ce60fbd7413 (patch) | |
tree | 539c4a3fdf1756ae79770d5c4aaf6366f1d1525e /archive/2.vm/continuation2.mu | |
parent | 8846a7f85cc04b77b2fe8a67b6d317723437b00c (diff) | |
download | mu-6e1eeeebfb453fa7c871869c19375ce60fbd7413.tar.gz |
5485 - promote SubX to top-level
Diffstat (limited to 'archive/2.vm/continuation2.mu')
-rw-r--r-- | archive/2.vm/continuation2.mu | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/archive/2.vm/continuation2.mu b/archive/2.vm/continuation2.mu new file mode 100644 index 00000000..45a65e9f --- /dev/null +++ b/archive/2.vm/continuation2.mu @@ -0,0 +1,37 @@ +# 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 +] |