2017-11-06 09:28:53 +00:00
|
|
|
# Example program showing that a 'paused' continuation can be 'resumed'
|
|
|
|
# multiple times from the same point (but with changes to data).
|
|
|
|
#
|
2017-11-25 18:17:23 +00:00
|
|
|
# To run:
|
|
|
|
# $ git clone https://github.com/akkartik/mu
|
|
|
|
# $ cd mu
|
|
|
|
# $ ./mu continuation2.mu
|
|
|
|
#
|
2017-11-06 09:28:53 +00:00
|
|
|
# Expected output:
|
|
|
|
# 1
|
|
|
|
# 2
|
|
|
|
# 3
|
2017-11-03 07:40:05 +00:00
|
|
|
|
|
|
|
def main [
|
|
|
|
local-scope
|
2018-06-17 18:20:53 +00:00
|
|
|
l:&:list:num <- copy null
|
2017-11-03 07:40:05 +00:00
|
|
|
l <- push 3, l
|
|
|
|
l <- push 2, l
|
|
|
|
l <- push 1, l
|
2017-12-15 08:15:47 +00:00
|
|
|
k:continuation <- call-with-continuation-mark 100/mark, create-yielder, l
|
2017-11-03 07:40:05 +00:00
|
|
|
{
|
|
|
|
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
|
2017-12-04 07:25:40 +00:00
|
|
|
load-inputs
|
2017-12-15 08:15:47 +00:00
|
|
|
return-continuation-until-mark 100/mark
|
2018-06-17 18:20:53 +00:00
|
|
|
done? <- equal l, null
|
|
|
|
return-if done?, 0/dummy
|
2017-11-03 07:40:05 +00:00
|
|
|
n <- first l
|
|
|
|
l <- rest l
|
|
|
|
]
|