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,2ac407a2a34565a9 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.134.225 with SMTP id pn1mr1822546pbb.7.1331282477539; Fri, 09 Mar 2012 00:41:17 -0800 (PST) Path: h9ni5581pbe.0!nntp.google.com!news1.google.com!goblin3!goblin.stu.neva.ru!news-1.dfn.de!news.dfn.de!news.uni-weimar.de!not-for-mail From: stefan-lucks@see-the.signature Newsgroups: comp.lang.ada Subject: Re: Array Help? Date: Fri, 9 Mar 2012 09:48:37 +0100 Organization: Bauhaus-Universitaet Weimar Message-ID: References: <10615783-d4a9-4cbd-8971-53ba1100d6a0@b18g2000vbz.googlegroups.com> <17412419.40.1330534213855.JavaMail.geo-discussion-forums@vbva11> Reply-To: stefan-lucks@see-the.signature NNTP-Posting-Host: medsec1.medien.uni-weimar.de Mime-Version: 1.0 X-Trace: tigger.scc.uni-weimar.de 1331282477 8143 141.54.178.228 (9 Mar 2012 08:41:17 GMT) X-Complaints-To: news@tigger.scc.uni-weimar.de NNTP-Posting-Date: Fri, 9 Mar 2012 08:41:17 +0000 (UTC) X-X-Sender: lucks@medsec1.medien.uni-weimar.de In-Reply-To: Content-Type: TEXT/PLAIN; charset=US-ASCII Date: 2012-03-09T09:48:37+01:00 List-Id: On Thu, 8 Mar 2012, Randy Brukardt wrote: [...] > wrote: > > 1. Testing > > > > When you declare > > > > procedure Sort(Items: in out array(Positive range <>) of T) > > Let's hope you never do that, because anonymous types are the bane of Ada. > And you surely can't do it today! OK, the real thing would look about like that: generic type Element_Type is (<>); type Index_Type is (Positive range <>); type Collection_Type is array(Index_Type range <>) of Element_Type; with function "<"(Left, Right : Element_Type) return Boolean is <>; function Sort(Items : Collection_Type) return Collection_Type; > > in a package specification, and you try to write a proper black-box test, > > you need *more* test cases then when you do the same with another popular > > language. > > Right. Bob's suggestion for some semi-constrained array subtype would fix > that. But note that it was killed in Ada 95 in part because the > implementation needed was essentially a record type with some sort of magic > indexing. Which was a mess. Would it ease the implementation if you constrain the start index to some fixed value, such as Index_Type'First? [...] > > procedure Sort(Items: in out array(generic Positive range <>) of T); > Again, anonymous types are a disaster in Ada, and there is no way that we > should have more of them. I would strongly hope that this never appears even > in Ada 2525. ;-) Sorry for using anonymous arrays. I hardly ever do this in real code. Please change the above code to generic type Element_Type is (<>); type Collection_Type is array(generic Positive range <>) of Element_Type; with function "<"(Left, Right : Element_Type) return Boolean is <>; function Sort(Items : Collection_Type) return Collection_Type; The issue is the same: > > Sort(X) should be callable if the index type of X is any discrete type, > > except when the index type is too large (i.e., X has more than > > Positive'Last elements). > > If you want that, you need to declare that. Positive is a numeric type, and > thus has "+" and "-" available; it is never going to be allowed to match > "any discrete type" which includes enumeration types. > > It's plenty easy to write a generic like this (see the predefined ones for > examples), so I fail to see what possible need you are addressing here. It is a readability issue. I frequently use arrays with different index types, that I need to sort, or to search for the same item being stored more than once ... Having to instantiate, say, the same Sort procedure several times makes the program less readable. But I agree with you that that is a minor issue, and that Bob's suggestion seems to solve the testing thing quite well. -- ---- Stefan.Lucks (at) uni-weimar.de, University of Weimar, Germany ---- ------ I love the taste of Cryptanalysis in the morning! ------