/** This actor implements the sieve of Eratosthenes. @author JWJ */ actor PrimeSieve () Integer Input ==> Integer Output: // Initialize the filter function to one that returns false: // the first token will always be let through. [Integer --> Boolean] filter := lambda (Integer a) --> Boolean : false end; function divides (Integer a, Integer b) --> Boolean : b mod a = 0 end // Simply remove the token if the filter function returns true. action [a] ==> [] guard filter(a) end // Let the token through if the filter function returns false. action [a] ==> [a] guard not filter(a) var [Integer --> Boolean] f = filter do // After saving the current filter function in f, create a new filter // that is the logical or of the previous one, and an application of the // predicate with the current token as the second argument. filter := lambda(Integer b) --> Boolean: f(b) or divides(a, b) end; end end