comp.lang.ada
 help / color / mirror / Atom feed
* Prime sieve
@ 2015-05-27 14:35 montgrimpulo
  2015-05-27 14:58 ` Paul Rubin
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: montgrimpulo @ 2015-05-27 14:35 UTC (permalink / raw)


with Ada.Text_IO;         use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure Primes_by_Sieve is
   task type Sieve is
      entry Pass_on (Int : Integer);
   end Sieve;

   task P6n;

   type Sieve_Ptr is access Sieve;

   function Get_New_Sieve return Sieve_Ptr is
   begin
      return new Sieve;
   end Get_New_Sieve;

   task body P6n is
      Limit : constant Integer := 2580976;
      Num   : Integer          := 1;
      S     : Sieve_Ptr        := new Sieve;
   begin
      while Num <= Limit loop
         S.Pass_on (6 * Num - 1);
         S.Pass_on (6 * Num + 1);
         Num := Num + 1;
      end loop;
   end P6n;

   task body Sieve is
      New_Sieve  : Sieve_Ptr;
      Prime, Num : Integer;
   begin
      accept Pass_on (Int : Integer) do
         Prime := Int;
      end Pass_on;
      New_Line;
      Put (Prime);
      loop
         select
            accept Pass_on (Int : Integer) do
               Num := Int;
            end Pass_on;
         or
            terminate;
         end select;
         exit when Num rem Prime /= 0;
      end loop;

      New_Sieve := Get_New_Sieve;
      New_Sieve.Pass_on (Num);

      loop
         select
            accept Pass_on (Int : Integer) do
               Num := Int;
            end Pass_on;
         or
            terminate;
         end select;
         if Num rem Prime /= 0 then
            New_Sieve.Pass_on (Num);
         end if;
      end loop;
   end Sieve;

begin
   null;
end Primes_by_Sieve;

The program above stops normally long before Limit (2580976). Which internal 
restrictions do apply (GNAT, GPS 4.9.1) ?

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-05-27 17:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-27 14:35 Prime sieve montgrimpulo
2015-05-27 14:58 ` Paul Rubin
2015-05-27 15:01 ` Egil H H
2015-05-27 15:14 ` J-P. Rosen
2015-05-27 17:39 ` Jeffrey R. Carter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox