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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,5f5a48f21d7f7525 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!news4.google.com!feeder.news-service.com!85.214.198.2.MISMATCH!eternal-september.org!.POSTED!not-for-mail From: "J-P. Rosen" Newsgroups: comp.lang.ada Subject: Re: Inferring array index type from array object Date: Wed, 23 Jun 2010 11:03:17 +0200 Organization: Adalog Message-ID: References: <6b20ed09-efc1-4df7-90f9-5e141482e8d0@d37g2000yqm.googlegroups.com> <1305oqccr1h2t$.x33x4oxwd84d$.dlg@40tude.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Injection-Date: Wed, 23 Jun 2010 09:03:27 +0000 (UTC) Injection-Info: mx03.eternal-september.org; posting-host="Dn22F68J9CHYFQQlT81DGA"; logging-data="3399"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+saKF71pYm1Bl7Gocc9TbF" User-Agent: Thunderbird 2.0.0.24 (Windows/20100228) In-Reply-To: <1305oqccr1h2t$.x33x4oxwd84d$.dlg@40tude.net> Cancel-Lock: sha1:peaOExuIMWkf0n85aXjB3YJ2I7U= Xref: g2news2.google.com comp.lang.ada:12853 Date: 2010-06-23T11:03:17+02:00 List-Id: Dmitry A. Kazakov a �crit : >> I would like to declare I as a free variable instead and I would >> expect some symmetry in the language by doing this: >> >> I : S'Range := S'First; > > subtype Index_Span is Integer range S'Range; > I : Index_Span := S'First; Or simply: I : Positive range S'Range; >> 1. What is the standard justification for this assymetry? This is a simplification of loops, to avoid some typing to the user. Think of it the other way round: since a for loop involves the declaration of an object, the type should always be explicitely declared (a coding rule that I apply - of course checkable by AdaControl): for I in positive range 1..10 loop ... for I in positive range S'Range loop ... So it is really symetrical, except that in the case of a loop, you are allowed to "simplify" by omitting the " range" part - forcing the compiler to deduce the type from the range, which is not a good idea IMHO. >> 2. Is it possible to declare the index variable without hardcoding the >> index type (that is, to infer it from the array object)? > There is no point in doing this, since the type of the array /is/ hardcoded anyway. You could allow the same "simplification" as for loops, but as mentionned above, I prefer the other way round: always explicitely give the type name. -- --------------------------------------------------------- J-P. Rosen (rosen@adalog.fr) Visit Adalog's web site at http://www.adalog.fr