From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Generic procedures and their parameters
Date: Thu, 7 Sep 2006 09:47:45 +0200
Date: 2006-09-07T09:47:45+02:00 [thread overview]
Message-ID: <86vm3vplnvnr.1pdeayojfjn09$.dlg@40tude.net> (raw)
In-Reply-To: I_CdnXhjVN2_FWLZnZ2dnUVZ_qKdnZ2d@comcast.com
On Wed, 6 Sep 2006 19:47:14 -0700, Steve wrote:
> "Maciej Sobczak" <no.spam@no.spam.com> wrote in message
> news:edm273$fee$1@sunnews.cern.ch...
>> Hi,
>>
>> I have found the following signature for the sorting procedure:
>>
>> eneric
>> type Index_Type is (<>);
>> type Element_Type is private;
>> type Array_Type is array (Index_Type range <>) of Element_Type;
>> with function "<" (Left, Right : in Element_Type) return Boolean is <>;
>> procedure Sort(To_Sort : in out Array_Type);
>>
>> My question is: what's the purpose of the third parameter (Array_Type)?
>> Isn't it implied by the first two and therefore just redundant?
>
> I prefer:
>
> generic
> type Index_Type is (<>);
> type Collection_Type is private;
> firstIndex : Index_Type;
> lastIndex : Index_Type;
> with function In_Order( list : Collection_Type; i, j : Index_Type )
> return Boolean;
> procedure Swap( list : in out Collection_Type; i, j : Index_Type );
> procedure Sort( list : in out Collection_Type );
>
> This avoids the declaration of the array altogether, and is usable for any
> list that may be referenced by index.
Ah, that's an "abstract generic array" thing. If more that just Sort is
needed one goes as:
generic
type Index_Type is (<>);
type Element_Type is private;
Null_Element : Element_Type;
type Collection_Type is private;
with function First (X : Collection_Type) return Index_Type is <>;
with function Last (X : Collection_Type) return Index_Type is <>;
with function Get (X : Collection_Type) return Element_Type is <>;
with procedure Set (X : in out Collection_Type; Y : Element_Type) is <>;
package Generic_Collection is
-- Nothing here. It is an "abstract" package
end Generic_Collection;
Then Sort becomes a child:
generic
with function "<" (Left, Right : Element_Type) return Boolean;
procedure Generic_Collection.Sort (X : in out Collection_Type);
Unfortunately, Element_Type reappears.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
prev parent reply other threads:[~2006-09-07 7:47 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-09-06 8:51 Generic procedures and their parameters Maciej Sobczak
2006-09-06 9:43 ` Dmitry A. Kazakov
2006-09-06 12:36 ` Maciej Sobczak
2006-09-06 13:11 ` Robert A Duff
2006-09-06 14:14 ` Maciej Sobczak
2006-09-06 15:09 ` Dmitry A. Kazakov
2006-09-06 16:35 ` Georg Bauhaus
2006-09-07 7:32 ` Dmitry A. Kazakov
2006-09-07 6:48 ` Georg Bauhaus
2006-09-07 10:19 ` Dmitry A. Kazakov
2006-09-08 9:11 ` Maciej Sobczak
2006-09-08 10:19 ` Dmitry A. Kazakov
2006-09-09 14:49 ` Robert A Duff
2006-09-09 15:34 ` Dmitry A. Kazakov
2006-09-09 23:26 ` Jeffrey R. Carter
2006-09-10 11:49 ` Robert A Duff
2006-09-10 19:43 ` Jeffrey R. Carter
2006-09-06 13:02 ` Robert A Duff
2006-09-06 14:09 ` Dmitry A. Kazakov
2006-09-08 3:35 ` Randy Brukardt
2006-09-08 7:21 ` Dmitry A. Kazakov
2006-09-09 1:29 ` Randy Brukardt
2006-09-09 7:14 ` Dmitry A. Kazakov
2006-09-09 14:32 ` Robert A Duff
2006-09-06 12:56 ` Robert A Duff
2006-09-07 2:47 ` Steve
2006-09-07 7:47 ` Dmitry A. Kazakov [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox