Skip to content

Instantly share code, notes, and snippets.

@munificent
Forked from dscleaver/Sieve.mag
Created June 14, 2011 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save munificent/1025344 to your computer and use it in GitHub Desktop.
Save munificent/1025344 to your computer and use it in GitHub Desktop.
Implementation of the Sieve of Eratosthenes in Magpie
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