comp.lang.ada
 help / color / mirror / Atom feed
From: stefan-lucks@see-the.signature
Subject: Re: What's wrong with my code?
Date: Mon, 28 Apr 2008 17:18:31 +0200
Date: 2008-04-28T17:18:31+02:00	[thread overview]
Message-ID: <Pine.LNX.4.64.0804281659320.27398@medsec1.medien.uni-weimar.de> (raw)
In-Reply-To: <5a3b83ab-c9eb-448d-8e01-093df11bd3d2@b1g2000hsg.googlegroups.com>

On Mon, 28 Apr 2008, amal.alphonse@gmail.com wrote:

> Sorry if I'm posting in the wrong forum.

You are perfectly right here. 

> with Ada.Text_IO, Ada.Integer_Text_IO;
> with SelectionP;
> procedure SelectionPUser is

Replace the following line

>    package IntSelectionP is new SelectionP(Integer, Ada.Text_IO.Put);

by

   procedure Put_Int(I: Integer) is
   begin
      Ada.Integer_Text_IO.Put(I);
   end Put_Int;

   package Int_SelectionP is new X(Integer, Put_Int);

The specification of Put in Ada.Integer_Text_IO is 
   
         procedure Put(Item  : in Num;	
                       Width : in Field := Default_Width;
                       Base  : in Number_Base := Default_Base);

Thanks to the default parameters, you can just write 
"Ada.Integer_Text_IO.Put(I);" to *call* this procedure Put. But using the 
same Put as a generic parameter appears to be different ...

> begin
>    Ada.Text_IO.New_Line;
> end SelectionPUser;

>    procedure Print (A: in out My_Array) is

Nitpick: this should be 
     procedure Print(A in My_Array) is 
to conform with the specification. 

Additional point: Most Ada programmers depreciate identifiers like 
IntSelectionP, SelectionP, ... but prefer to use underscores: 
Int_Selection_P, Selection_P. This improves readability and copes well 
with the case-insensitivity of Ada identifiers. (E.g., for ada Selections 
and SelectionS are the same, but Selections and Selection_S are different. 
I currently can't find a better example, but I hope you get the idea.)

> Also, is my code correct if my purpose is to use the package to create
> arrays of different elements (integer, character, etc) and use the
> procedures Find_Min and Sort and Print on them?

I guess you are going to compare your elements? Then you'll want to 
specify another generic parameter (in addition to the type Element and the 
procedure Element_Put), such as

  function "<"(Left, Right: Element) return Boolean;





-- 
------ Stefan Lucks   --  Bauhaus-University Weimar  --   Germany  ------
               Stefan dot Lucks at uni minus weimar dot de
------  I  love  the  taste  of  Cryptanalysis  in  the  morning!  ------




  reply	other threads:[~2008-04-28 15:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-28 14:42 What's wrong with my code? amal.alphonse
2008-04-28 15:18 ` stefan-lucks [this message]
2008-04-28 15:22   ` stefan-lucks
2008-04-28 15:24     ` stefan-lucks
2008-04-28 15:23 ` george.priv
2008-04-28 16:52 ` Ivan Levashew
2008-04-29  9:18   ` Ludovic Brenta
2008-04-29  5:30 ` christoph.grein
2008-04-29  9:31 ` Ludovic Brenta
2008-04-29 10:33 ` amal.alphonse
replies disabled

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