comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: initialize an array (1-D) at elaboration using an expression based on the index?
Date: Wed, 10 Nov 2010 07:51:07 -0800 (PST)
Date: 2010-11-10T07:51:07-08:00	[thread overview]
Message-ID: <82e746ff-a4eb-4570-8016-78930977def1@35g2000prb.googlegroups.com> (raw)
In-Reply-To: 4cdaad27$0$6979$9b4e6d93@newsspool4.arcor-online.net

On Nov 10, 6:33 am, Georg Bauhaus <rm.dash-bauh...@futureapps.de>
wrote:
> On 16.10.10 02:16, Adam Beneschan wrote:
>
> > 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));
>
> I have an array of library level task objects.
> Each task is supposed have a unique identifying number,
> fixed and assigned at compile time.  Perhaps starting from
> a task type definition like the following one:
>
>    task T (Identity : Job_Id := No_Job) is ...
>
> Could some variation of the (for ...) expression solve this,
> i.e. provide the initial value?
>
>    Jobs : array (Job_Id) of T := (for D in Job_Id => ???(D));
>
> Borrowing from limited types, I'd think "???" might be just "T"?
>
>    Jobs : array (Job_Id) of T := (for D in Job_Id => T (D));

This seems like an orthogonal problem.  That is, it's a problem even
when arrays aren't involved.  If you have a record that contains a
task---say you want to create a linked list:

   type Rec;
   type Rec_P is access all Rec;
   type Rec is record
      Job  : T;        -- T is defined with a discriminant
      Link : Rec_P;
   end record;

and you want to create an object of this type and initialize it with
an aggregate:

   Single_Job : aliased Rec := (T(J), null);

where J is some variable or parameter or something, I don't think
there's any current syntax that would allow this.  But I think you can
set up a function:

   function Task_With_ID (Identity : Job_ID := No_Job) return T is
   begin
      return X : T(Identity);
   end;

and use that in your aggregate:

   Single_Job : aliased Rec := (Task_With_ID(J), null);

Warning: I have not tried this.

If this does work, then assuming that a "for" syntax is added for
array aggregates, it can be used in conjunction with a function call
as above.  If you don't like the need for a function call and would
like a different syntax, then one can be proposed, but any solution
should also work in the non-array case.  So this doesn't really have
anything to do with array initialization.

                           -- Adam








  reply	other threads:[~2010-11-10 15:51 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
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 [this message]
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