2017-11-06 09:28:53 +00:00
|
|
|
# Example program showing that 'return-continuation-until-mark' can 'pause' a
|
2017-11-03 07:40:05 +00:00
|
|
|
# function call, returning a continuation, and that calling the continuation
|
|
|
|
# can 'resume' the paused function call.
|
2017-11-06 09:28:53 +00:00
|
|
|
#
|
2017-11-25 18:17:23 +00:00
|
|
|
# To run:
|
|
|
|
# $ git clone https://github.com/akkartik/mu
|
|
|
|
# $ cd mu
|
|
|
|
# $ ./mu continuation1.mu
|
|
|
|
#
|
2017-11-06 09:28:53 +00:00
|
|
|
# Expected output:
|
|
|
|
# 1
|
2017-11-03 07:40:05 +00:00
|
|
|
|
|
|
|
def main [
|
|
|
|
local-scope
|
2017-12-15 08:15:47 +00:00
|
|
|
k:continuation <- call-with-continuation-mark 100/mark, create-yielder
|
2017-11-17 07:39:46 +00:00
|
|
|
x:num <- call k # should return 1
|
|
|
|
$print x 10/newline
|
2017-11-03 07:40:05 +00:00
|
|
|
]
|
|
|
|
|
2017-11-17 07:39:46 +00:00
|
|
|
def create-yielder -> n:num [
|
2017-11-03 07:40:05 +00:00
|
|
|
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
|
2017-11-17 07:39:46 +00:00
|
|
|
return 1
|
2017-11-03 07:40:05 +00:00
|
|
|
]
|