about summary refs log tree commit diff stats
path: root/continuation1.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2017-11-03 00:40:05 -0700
committerKartik K. Agaram <vc@akkartik.com>2017-11-03 01:49:36 -0700
commita3195d440d2f0e99400db78e5a4386691c94a9a0 (patch)
tree00ee3bff640edccd27abaa387073418105699334 /continuation1.mu
parent850822ffbfd441d05161452be28b54f882b1b378 (diff)
downloadmu-a3195d440d2f0e99400db78e5a4386691c94a9a0.tar.gz
4103 - continuations no longer cause memory corruption
Diffstat (limited to 'continuation1.mu')
-rw-r--r--continuation1.mu23
1 files changed, 23 insertions, 0 deletions
diff --git a/continuation1.mu b/continuation1.mu
new file mode 100644
index 00000000..23e92f8f
--- /dev/null
+++ b/continuation1.mu
@@ -0,0 +1,23 @@
+# example program showing that 'return-continuation-until-mark' can 'pause' a
+# function call, returning a continuation, and that calling the continuation
+# can 'resume' the paused function call.
+
+def main [
+  local-scope
+  k:continuation <- call-with-continuation-mark create-yielder
+  {
+    x:num, done?:bool <- call k  # should return 1
+    break-if done?
+    $print x 10/newline
+    loop
+  }
+]
+
+def create-yielder -> n:num, done?:bool [
+  local-scope
+  load-ingredients
+  n <- copy 0
+  return-continuation-until-mark
+  done?:bool <- greater-or-equal n, 3
+  n <- add n, 1
+]