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 pn1mr5018216pbb.7.1331205197204; Thu, 08 Mar 2012 03:13:17 -0800 (PST) Path: h9ni2156pbe.0!nntp.google.com!news2.google.com!goblin2!goblin.stu.neva.ru!news.unit0.net!news.uni-stuttgart.de!news-2.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: Thu, 8 Mar 2012 12:20:28 +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 1331205197 15745 141.54.178.228 (8 Mar 2012 11:13:17 GMT) X-Complaints-To: news@tigger.scc.uni-weimar.de NNTP-Posting-Date: Thu, 8 Mar 2012 11:13: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-08T12:20:28+01:00 List-Id: On Wed, 7 Mar 2012, Randy Brukardt wrote: > "Robert A Duff" wrote in message > news:wccy5rls0hl.fsf@shell01.TheWorld.com... > > stefan-lucks@see-the.signature writes: > >> procedure Sort(Items: in out array(generic Positive range <>) of T) is > > > > Interesting idea. > > Can't you do this with a type conversion to an appropriate constrained array > subtype? (Such conversions slide.) I suppose it could be a pain to declare > such a subtype in front of every call, but it is a trick I've used a some > cases (usually in wrappers) to force sliding on arguments. Can you explain a bit more? > I suppose a more convinient way to force that would be helpful. Beyond the inconvenience, there are two further issues: 1. Testing When you declare procedure Sort(Items: in out array(Positive range <>) of T) 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. One of the additional test cases could look like declare X: array (Positive range Positive'last-2 .. Positive'Last) := ...; Y: array (Positive range Positive'last-2 .. Positive'Last) := ...; begin Sort(X); Assert(X=Y); end; Some time ago, I have actually been bitten by forgetting such a test case. So the sad reality is that there is a property where Ada makes testing harder than, say, C or C++. 2. Generality Given the (Ada 2020?) specification procedure Sort(Items: in out array(generic Positive range <>) of T); 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). -- ---- Stefan.Lucks (at) uni-weimar.de, University of Weimar, Germany ---- ------ I love the taste of Cryptanalysis in the morning! ------