Bruce & Breeanna Rennie wrote:
Greetings to all for the new year,
I have just been reading the paper by Melissa E. O'Neill called "The
Genuine Sieve of Eratosthenes." This paper was written from the
perspective of a functional programming paradigm. It got me thinking
about how to write the corresponding Icon/UnIcon program.
Has anyone seen or done an Icon/UnIcon implementation of this algorithm
using co-expression?
I am trying to build one now.
How close is the attached? I wrote this as part of my dissertation back
in the late 70's. It's a brute force sieve that adds co-expressions to
the sieve as primes are discovered by the sieve.
--
--
Steve Wampler {...@tapestry.tucson.az.us}
The gods that smiled upon your birth are laughing now. -- fortune cookie
## prime number sieve (using co-expressions)
global num, cascade, source, nextfilter
procedure main()
source := create { # start the cascade on possible primes
every num := seq(2) do
@@(nextfilter := create !cascade)
@&main
}
cascade := list()
put(cascade, create sink()) # the first number (2) is assumed to
# be a prime.
@source
end
procedure sink() # have a prime, display it and
local prime # add a new filter to the cascade
repeat {
write(prime := num)
put(cascade, create filter(prime))
cascade[-2] :=: cascade[-1]
@source
}
end
procedure filter(prime) # test to see if num is a multiple
# of prime
repeat {
if num % prime = 0 then @source
else @@nextfilter
}
end
------------------------------------------------------------------------------
_______________________________________________
Unicon-group mailing list
Unicon-group@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/unicon-group