-
-
Save munificent/1025344 to your computer and use it in GitHub Desktop.
Implementation of the Sieve of Eratosthenes in Magpie
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
import async | |
def spawnGenerator(channel is Channel) | |
run with for i = count(from: 2, by: 1) do channel send(i) | |
end | |
def spawnFilter(in is Channel, prime is Int) | |
val out = Channel new(1) | |
run with | |
while true do | |
val i = in receive | |
if (i % prime) != 0 then out send(i) | |
end | |
end | |
out | |
end | |
val channel = Channel new(1) | |
spawnGenerator(channel) | |
for i = 1 to(100) do | |
val prime = channel receive | |
print(prime) | |
channel = spawnFilter(channel, prime) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment