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.4 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,7b6305d0d57a9f34 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.30.34 with SMTP id p2mr6993498pbh.4.1319915954926; Sat, 29 Oct 2011 12:19:14 -0700 (PDT) Path: p6ni26287pbn.0!nntp.google.com!news1.google.com!goblin2!goblin1!goblin.stu.neva.ru!news.tornevall.net!.POSTED!not-for-mail From: Jeffrey Carter Newsgroups: comp.lang.ada Subject: Re: Normalizing array indices Date: Sat, 29 Oct 2011 12:18:03 -0700 Organization: TornevallNET - http://news.tornevall.net Message-ID: References: <4eabab47$0$30757$ba4acef3@reader.news.orange.fr> NNTP-Posting-Host: 7e98ebcec61e3546af12ffc067a5f52c Mime-Version: 1.0 X-Trace: c30c8aa9a23fff60f94470da2c1825a4 X-Complaints-To: abuse@tornevall.net User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.23) Gecko/20110922 Thunderbird/3.1.15 X-Complaints-Language: Spoken language is english or swedish - NOT ITALIAN, FRENCH, GERMAN OR ANY OTHER LANGUAGE! In-Reply-To: <4eabab47$0$30757$ba4acef3@reader.news.orange.fr> X-UserIDNumber: 1738 X-Validate-Post: http://news.tornevall.net/validate.php?trace=c30c8aa9a23fff60f94470da2c1825a4 X-Complaints-Italiano: Non abbiamo padronanza della lingua italiana - se mandate una email scrivete solo in Inglese, grazie X-Posting-User: 0243687135df8c4b260dd4a9a93c79bd Xref: news1.google.com comp.lang.ada:18751 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Date: 2011-10-29T12:18:03-07:00 List-Id: On 10/29/2011 12:29 AM, Pascal Obry wrote: > > generic > type Element_Type is private; > type Sort_Array_Type is array (Positive range<>) of Element_Type; > with function "<" (Left, Right: Element_Type) return Boolean is<>; > procedure Sort(A: in out Sort_Array_Type) The problem is the use of Positive for the generic formal array index. One thinks of numbers as being infinite, so failing to think about the effect of adding 1 to an index is natural. Why should a general-purpose sort procedure restrict the client to arrays indexed by Positive? generic -- Sort type Element is private; type Index is (<>); type Sort_List is array (Index range <>) of Element; with function "<" (Left : Element; Right : Element) return Boolean is <>; procedure Sort (List : in out Sort_List); Now the developer is forced to think in terms of Index being finite, and so the cases of trying to take the Succ to Index'Last and the Pred of Index'First. The PragmAda Reusable Components contain insertion, heap, quick, and radix sorts, all of which allow any discrete subtype for the indices and handle Index'Last correctly: http://pragmada.co.cc/ -- Jeff Carter "I don't know why I ever come in here. The flies get the best of everything." Never Give a Sucker an Even Break 102