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!p26g2000yqb.googlegroups.com!not-for-mail From: Phil Clayton Newsgroups: comp.lang.ada Subject: Re: initialize an array (1-D) at elaboration using an expression based on the index? Date: Sat, 16 Oct 2010 03:08:49 -0700 (PDT) Organization: http://groups.google.com Message-ID: <04e9d3fb-8a43-4a95-adc0-e5604dd4a692@p26g2000yqb.googlegroups.com> References: <4b8f7f06-a817-4545-9fc6-67740c67b9d3@a4g2000prm.googlegroups.com> NNTP-Posting-Host: 91.110.179.75 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1287223730 31556 127.0.0.1 (16 Oct 2010 10:08:50 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 16 Oct 2010 10:08:50 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: p26g2000yqb.googlegroups.com; posting-host=91.110.179.75; posting-account=v7gx3AoAAABfjb9m5b7l_Lt2KVEgQBIe User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.0.15) Gecko/2009102704 Fedora/3.0.15-1.fc10 Firefox/3.0.15,gzip(gfe) Xref: g2news2.google.com comp.lang.ada:15534 Date: 2010-10-16T03:08:49-07:00 List-Id: On Oct 16, 1:16=A0am, Adam Beneschan wrote: > On Oct 15, 4:31=A0pm, "Vinzent Hoefler" > > > domaingrabbing.de> wrote: > > On Sat, 16 Oct 2010 01:03:52 +0200, Nasser M. Abbasi w= rote: > > > > I was wondering if in Ada I can initialize some array, where I can fi= ll > > > the content of each entry in the array based on some function of the = index? > > > 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 t= he > > 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 evaluat= ion > > 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. ... There was a recent discussion about exactly this on c.l.a. that spawned off a thread on conditional expressions: http://groups.google.com/group/comp.lang.ada/browse_thread/thread/334f90127= 42e58fc/bc4410d521cd9e9c#bc4410d521cd9e9c Phil