diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2017-11-05 01:47:03 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2017-11-05 01:47:03 -0800 |
commit | 4c5136859dce2bc752e60b450f64c62ee7e66815 (patch) | |
tree | 20553425d104c12dace3ebf59e515364fe797c4d /continuation4.mu | |
parent | 504292f6f1a283af39de305879b50f16d6180caa (diff) | |
download | mu-4c5136859dce2bc752e60b450f64c62ee7e66815.tar.gz |
4107
Return other values along with the current continuation.
Diffstat (limited to 'continuation4.mu')
-rw-r--r-- | continuation4.mu | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/continuation4.mu b/continuation4.mu new file mode 100644 index 00000000..5957c1be --- /dev/null +++ b/continuation4.mu @@ -0,0 +1,39 @@ +# example program showing 'return-continuation-until-mark' return other values +# alongside continuations + +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 + # Our current primitives can lead to gnarly code to ensure that we always + # statically match a continuation call with a 'return-continuation-until-mark'. + # Try to design functions to either always return or always return continuation. + { + # should we have conditional versions of return-continuation-until-mark + # analogous to return-if and return-unless? Names get really long. + break-unless done? + return-continuation-until-mark 0, done? + return 0, done? # just a guard rail; should never execute + } + n <- first l + l <- rest l + return-continuation-until-mark n, done? + loop + } +] |