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: a07f3367d7,d00514eb0749375b X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!a4g2000prm.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: initialize an array (1-D) at elaboration using an expression based on the index? Date: Fri, 15 Oct 2010 17:16:08 -0700 (PDT) Organization: http://groups.google.com Message-ID: <4b8f7f06-a817-4545-9fc6-67740c67b9d3@a4g2000prm.googlegroups.com> References: NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1287188168 1742 127.0.0.1 (16 Oct 2010 00:16:08 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 16 Oct 2010 00:16:08 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: a4g2000prm.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:15524 Date: 2010-10-15T17:16:08-07:00 List-Id: On Oct 15, 4:31=A0pm, "Vinzent Hoefler" wrote: > On Sat, 16 Oct 2010 01:03:52 +0200, Nasser M. Abbasi wro= te: > > > I was wondering if in Ada I can initialize some array, where I can fill > > the content of each entry in the array based on some function of the in= dex? > > Not that I know of. > > At first, you don't have an index at the point of the expression, so > you can not parametrize a function with the "current" index returning the > appropriate value. > At second, if you try to be smart and provide a non-pure function that > counts the number of calls to it and provides an appropriate new return > value on each call, this is not guaranteed to work, because the evaluatio= n > order is "arbitrary". > > Still, you can use an array aggregate like: > > a: array(1..N) of float :=3D (1 =3D> Eval (1), 2 =3D> Eval (2), ...); > > but I wouldn't recommend that due to its lack of flexibility if the > index constraint changes. > > Vinzent. It seems like it would be simple to add syntax to array aggregates in the language like a : array(1..N) of Float :=3D (for I in 1..N =3D> Float(I)*Float(I)); The legality rules and rules about applicable index constraints would be the same as if "for I in" were not present. Perhaps someone has already made a similar proposal, but I can't find it. Since Ada 2012 is already putting "if" and "case" in expressions, though, it shouldn't be too big a leap to include "for" in an expression. Of course, it's too late to make it into Ada 2012, but perhaps I'll propose it for the next version of Ada (what is that going to be? Ada 2020, where we add all the features that we realize in hindsight that we should have added earlier? :-)). -- Adam