Created
June 24, 2020 01:21
-
-
Save anacrolix/ac4c5aad18e92af363aa965492ea5ddd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
actor Main | |
new create(env: Env) => | |
let chain = DivisibleFilter(2, Printer(env), env) | |
let g = Generator(100000000, chain) | |
actor Generator | |
new create(max: I, next: Next tag) => | |
var i: I = 2 | |
while i <= max do | |
next.apply(i) | |
i = i + 1 | |
end | |
actor Printer | |
let _env: Env | |
new create(env: Env) => | |
_env = env | |
be apply(i: I) => | |
_env.out.print(i.string()) | |
type I is U64 | |
interface Next | |
be apply(i: I) | |
actor DivisibleFilter | |
let _div: I | |
var _next: Next tag | |
var _is_last: Bool | |
let _env: Env | |
new create(div: I, next: Next tag, env: Env) => | |
_div = div | |
_next = next | |
_is_last = true | |
_env = env | |
be apply(i: I) => | |
// _env.out.print(_div.string()+" got "+i.string()) | |
if (i % _div) == 0 then | |
return | |
end | |
_next.apply(i) | |
if _is_last then | |
_next = DivisibleFilter(i, _next, _env) | |
_is_last = false | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment