From a3195d440d2f0e99400db78e5a4386691c94a9a0 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 3 Nov 2017 00:40:05 -0700 Subject: 4103 - continuations no longer cause memory corruption --- continuation2.mu | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 continuation2.mu (limited to 'continuation2.mu') diff --git a/continuation2.mu b/continuation2.mu new file mode 100644 index 00000000..dda9d566 --- /dev/null +++ b/continuation2.mu @@ -0,0 +1,27 @@ +# example program showing that a 'paused' continuation can be 'resumed' +# multiple times from the same point (but with changes to data) + +def main [ + local-scope + l:&:list:num <- copy 0 + l <- push 3, l + l <- push 2, l + l <- push 1, l + k:continuation <- call-with-continuation-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-ingredients + return-continuation-until-mark + done? <- equal l, 0 + return-if done?, 0 + n <- first l + l <- rest l +] -- cgit 1.4.1-2-gfad0