From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,39ed0c6d1b17bc59 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-07-14 18:36:45 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!stamper.news.atl.earthlink.net!harp.news.atl.earthlink.net!not-for-mail From: Richard Riehle Newsgroups: comp.lang.ada Subject: Re: HELP ! Problems with Get and Put in Generic Procedure Date: Mon, 14 Jul 2003 18:40:11 -0700 Organization: AdaWorks Software Engineering Message-ID: <3F135B7B.AE51E991@adaworks.com> References: <9f383bcd.0307101401.60625c77@posting.google.com> Reply-To: richard@adaworks.com NNTP-Posting-Host: 41.b2.41.e1 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Server-Date: 15 Jul 2003 01:36:45 GMT X-Mailer: Mozilla 4.7 [en] (Win98; I) X-Accept-Language: en Xref: archiver1.google.com comp.lang.ada:40275 Date: 2003-07-15T01:36:45+00:00 List-Id: I am including Tanya's message at the end of this reply. It is usually a design error to include the I/O capabilities in a generic component. It is a matter of loose coupling. Separate out the I/O portion of your design from the generic component. Add iterators to the component if you to traverse the entire entity. You can also add a current_item indicator to your component so you will be able to write a method to fill and clear the array one item at a time with an external procedure. Richard Riehle ---------------------------------------------------------------------------- Tanya wrote: > I am having problems compiling a program that uses a generic GetData > procedure. Inside this procedure I try to Get data from the keyboard > and store into an array. My generic specification and body both > compile fine...but when I try to instantiate the generic procedure in > the main driver, I get errors: > "procedure or entry name expected" and "expect valid subprogram name > in renaming". What am I doing wrong ?? I can't find any examples of > how to do this. Any help would be greatly appreciated !!! Thanks ! > > Here is my program: > > (generic spec file) ****************************************** > > GENERIC > > TYPE ElementType IS PRIVATE; -- any nonlimited type > TYPE IndexType IS ( <> ); -- any discrete type for > -- index value > TYPE ArrayType IS ARRAY (IndexType RANGE <>) OF ElementType; > > WITH PROCEDURE Read (Item : IN ElementType); > > PROCEDURE Get_Array_Generic (List : IN OUT ArrayType); > -- Input : Array type and input file stream. > -- Action: Will read in elements and store in array. > -- Output: Array filled with elements. > > (generic body file) ******************************************** > > PROCEDURE Get_Array_Generic (List : IN OUT ArrayType) IS > ------------------------------------------------------------------- > -- Input : Array type and input file stream. > -- Action: Will read in elements and store in array. > -- Output: Array filled with elements. > ------------------------------------------------------------------- > > Index : IndexType; > Element : ElementType; > > BEGIN -- Get_Array_Generic > > Index := List'Last; -- initialize array index to > -- first subscript > > FOR Index IN List'RANGE LOOP > > Read (Item => Element); -- read elements into array > > -- store data into the array > > List (Index) := Element; > > END LOOP; > > END Get_Array_Generic; > > (Main driver ) ******************************************** > > WITH Ada.Text_IO; > USE Ada.Text_IO; > WITH Ada.Integer_Text_IO; > USE Ada.Integer_Text_IO; > > PROCEDURE Generic_Test IS > ---------------------------------------------------------------------- > -- Input : None > -- Action: > -- Output: None > ---------------------------------------------------------------------- > > MaxInt : CONSTANT Integer := 10; > SUBTYPE IntegerRange IS Integer RANGE 1..MaxInt; > TYPE Integer_Array IS ARRAY (IntegerRange RANGE <>) OF Integer; > > > *** This is where I am having problems (in the instantiation) *** > > PROCEDURE GetIntegers IS NEW Get_Array_Generic > (ElementType => Integer, > IndexType => IntegerRange, > ArrayType => Integer_Array, > Read => Ada.Integer_Text_IO); > > > IntArray : Integer_Array(IntegerRange); > > TargetInteger : Integer; > > BEGIN -- Generic_Test > > Ada.Text_IO.Put (Item => "Please enter "); > Ada.Integer_Text_IO.Put (Item => MaxInt, Width => 2); > Ada.Text_IO.Put (Item => " integer values: "); > Ada.Text_IO.New_Line; > > GetIntegers (List => IntArray); > > END Generic_Test;