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-7-bit Path: g2news2.google.com!news3.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Vinzent Hoefler" 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 01:31:12 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit X-Trace: individual.net whIxkNgBwd7iuAE0VDGYRA7pEegBF/TrK/O7vfE9Qz3Yropubu Cancel-Lock: sha1:N4xU40KlWIZ4bWvpr3O9d/4zTIc= User-Agent: Opera Mail/10.62 (Win32) Xref: g2news2.google.com comp.lang.ada:15523 Date: 2010-10-16T01:31:12+02:00 List-Id: On Sat, 16 Oct 2010 01:03:52 +0200, Nasser M. Abbasi 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. -- There is no signature.