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!35g2000prb.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: Wed, 10 Nov 2010 07:51:07 -0800 (PST) Organization: http://groups.google.com Message-ID: <82e746ff-a4eb-4570-8016-78930977def1@35g2000prb.googlegroups.com> References: <4b8f7f06-a817-4545-9fc6-67740c67b9d3@a4g2000prm.googlegroups.com> <4cdaad27$0$6979$9b4e6d93@newsspool4.arcor-online.net> 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 1289404268 10837 127.0.0.1 (10 Nov 2010 15:51:08 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 10 Nov 2010 15:51:08 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: 35g2000prb.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:16393 Date: 2010-11-10T07:51:07-08:00 List-Id: On Nov 10, 6:33=A0am, Georg Bauhaus 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 :=3D (for I in 1..N =3D> 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. =A0Perhaps starting from > a task type definition like the following one: > > =A0 =A0task T (Identity : Job_Id :=3D No_Job) is ... > > Could some variation of the (for ...) expression solve this, > i.e. provide the initial value? > > =A0 =A0Jobs : array (Job_Id) of T :=3D (for D in Job_Id =3D> ???(D)); > > Borrowing from limited types, I'd think "???" might be just "T"? > > =A0 =A0Jobs : array (Job_Id) of T :=3D (for D in Job_Id =3D> 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 :=3D (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 :=3D No_Job) return T is begin return X : T(Identity); end; and use that in your aggregate: Single_Job : aliased Rec :=3D (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