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-Thread: 103376,91276ec2ea911d3f X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.hanau.net!news-fra1.dfn.de!newsfeed.ision.net!newsfeed2.easynews.net!ision!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Generic procedures and their parameters Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: Date: Thu, 7 Sep 2006 09:47:45 +0200 Message-ID: <86vm3vplnvnr.1pdeayojfjn09$.dlg@40tude.net> NNTP-Posting-Date: 07 Sep 2006 09:47:45 CEST NNTP-Posting-Host: 1cc817c4.newsspool2.arcor-online.net X-Trace: DXC=Fmgj?oiCMZBFJ3]dH>I?oEA9EHlD;3YcB4Fo<]lROoRA4nDHegD_]REIm7[\Y2l=ADDNcfSJ;bb[EFCTGGVUmh?DN\HXHJ4e80N7hb]cJHJ>?B X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:6491 Date: 2006-09-07T09:47:45+02:00 List-Id: On Wed, 6 Sep 2006 19:47:14 -0700, Steve wrote: > "Maciej Sobczak" 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