comp.lang.ada
 help / color / mirror / Atom feed
From: Phil Clayton <phil.clayton@lineone.net>
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)
Date: 2010-10-16T03:08:49-07:00	[thread overview]
Message-ID: <04e9d3fb-8a43-4a95-adc0-e5604dd4a692@p26g2000yqb.googlegroups.com> (raw)
In-Reply-To: 4b8f7f06-a817-4545-9fc6-67740c67b9d3@a4g2000prm.googlegroups.com

On Oct 16, 1:16 am, Adam Beneschan <a...@irvine.com> wrote:
> On Oct 15, 4:31 pm, "Vinzent Hoefler" <nntp-2010...@t-
>
>
>
> domaingrabbing.de> wrote:
> > On Sat, 16 Oct 2010 01:03:52 +0200, Nasser M. Abbasi <n...@12000.org> wrote:
>
> > > 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 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 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 evaluation
> > order is "arbitrary".
>
> > Still, you can use an array aggregate like:
>
> > a: array(1..N) of float := (1 => Eval (1), 2 => 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 := (for I in 1..N => 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/334f9012742e58fc/bc4410d521cd9e9c#bc4410d521cd9e9c

Phil



  parent reply	other threads:[~2010-10-16 10:08 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-15 23:03 initialize an array (1-D) at elaboration using an expression based on the index? Nasser M. Abbasi
2010-10-15 23:31 ` Vinzent Hoefler
2010-10-16  0:16   ` Adam Beneschan
2010-10-16  0:29     ` Nasser M. Abbasi
2010-10-16  1:47       ` Robert A Duff
2010-10-16  1:01     ` Randy Brukardt
2010-10-16 10:08     ` Phil Clayton [this message]
2010-10-18 15:03       ` Adam Beneschan
2010-10-19  6:29         ` Randy Brukardt
2010-10-20 20:01         ` Phil Clayton
2010-10-19 16:34     ` Britt Snodgrass
2010-10-19 18:05       ` Jeffrey Carter
2010-10-19 19:00         ` Vinzent Hoefler
2010-11-10 14:33     ` Georg Bauhaus
2010-11-10 15:51       ` Adam Beneschan
2010-11-10 17:19         ` Dmitry A. Kazakov
2010-11-10 18:03           ` Adam Beneschan
2010-11-11  1:07         ` Georg Bauhaus
2010-11-11  8:30           ` Dmitry A. Kazakov
2010-11-11 12:02           ` Robert A Duff
2010-11-11 14:19             ` Georg Bauhaus
2010-10-16  0:52 ` Jeffrey Carter
2010-10-16  0:54 ` Gene
2010-10-16  1:11   ` Vinzent Hoefler
2010-10-21 13:44 ` Chad  R. Meiners
2010-10-24 16:40   ` Shark8
2010-10-24 22:48     ` Phil Clayton
2010-10-25  2:23       ` Shark8
2010-10-29 23:26         ` Phil Clayton
2010-10-31 18:47           ` Shark8
2010-10-31 21:59             ` Georg Bauhaus
2010-11-01  0:45             ` Phil Clayton
2010-11-01  1:55               ` Shark8
2010-10-30  6:34         ` Brian Drummond
2010-10-31 19:00           ` Shark8
2010-10-31 18:09             ` (see below)
2010-10-31 19:35               ` Shark8
2010-10-31 22:47                 ` (see below)
2010-11-01  0:07                   ` Shark8
2010-10-31 23:21                     ` (see below)
2010-10-31 21:26             ` Brian Drummond
2010-11-12 18:10             ` Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox