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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c548fcf2944e2c9b X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!x41g2000hsb.googlegroups.com!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: What's wrong with my code? Date: Tue, 29 Apr 2008 02:31:23 -0700 (PDT) Organization: http://groups.google.com Message-ID: <09e534e4-9883-4da6-af46-ec4b53c74634@x41g2000hsb.googlegroups.com> References: <5a3b83ab-c9eb-448d-8e01-093df11bd3d2@b1g2000hsg.googlegroups.com> NNTP-Posting-Host: 153.98.68.197 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1209461483 1709 127.0.0.1 (29 Apr 2008 09:31:23 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 29 Apr 2008 09:31:23 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: x41g2000hsb.googlegroups.com; posting-host=153.98.68.197; posting-account=pcLQNgkAAAD9TrXkhkIgiY6-MDtJjIlC User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.3) Gecko/20040924,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:21109 Date: 2008-04-29T02:31:23-07:00 List-Id: > generic > type Element is private; > with procedure Element_Put(E : in Element); > package SelectionP is Others have explained why neither Ada.Text_IO.Put nor Ada.Integer_Text_IO.Put are acceptable actuals for Element_Put. Element_Put is only necessary for one subprogram (procedure Print). Yet, all users of your package must provide an actual for Element_Put even if they don't call Print. Similarly, Find_Min and Sort are likely to require a function "<" to compare Elements. So I suggest: generic type Element is private; package Selection_P is type Index_Type is range 0 .. 10; type My_Array is array (Index_Type) of Element; generic with function "<" (Left, Right : in Element) return Boolean is <>; procedure Find_Min (A : My_Array; Offset : in Index_Type; Pos : out Index_Type); procedure Swap (A : in out My_Array; First, Second : Index_Type); generic with function "<" (Left, Right : in Element) return Boolean is <>; procedure Sort (A : in out My_Array); generic with procedure Put (E : in Element) is <>; procedure Put (A : in My_Array); end Selection_P; The reason I didn't place "<" as a generic formal parameter of the package, but rather of Find_Min and Sort, is because you might want to find the maximum element but sort in ascending order, like this: package S is new Selection_P (Element => Integer); procedure Find_Max is new S.Find_Min ("<" => ">"); -- use ">" as the actual procedure Sort is new S.Sort; -- use the default "<", sort in ascending order procedure Put (J : in Integer) is begin Ada.Integer_Text_IO.Put (J); end Put; procedure Put is new S.Put; -- use the default HTH -- Ludovic Brenta.