#
#          S I E V E   O F   E R A T O S T H E N E S
#

#  This program illustrates the use of sets in implementing the
#  classical sieve algorithm for computing prime numbers.

procedure main()
   local limit, s, i
   limit := 100
   s := set()
   every insert(s,1 to limit)
   every member(s,i := 2 to limit) do
      every delete(s,i + i to limit by i)
   delete(s,1)
   primes := sort(s)
   write("There are ",*primes," primes in the first ",limit," integers.")
   write("The primes are:")
   every write(right(!primes,*limit + 1))
end
