From: Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: basic question on adding 2 arrays
Date: Sun, 13 Jul 2014 14:53:47 -0700
Date: 2014-07-13T14:53:47-07:00 [thread overview]
Message-ID: <lpuv5b$upo$1@dont-email.me> (raw)
In-Reply-To: <76d7dbf2-e6b8-4304-b90a-c29a5d129156@googlegroups.com>
On 07/13/2014 03:10 AM, AdaMagica wrote:
> On Sunday, July 13, 2014 8:33:57 AM UTC+2, Jeffrey Carter wrote:
>> function "+" (Left : in Base_Grid; Right : in Base_Grid) return Base_Grid with
>> Pre => Left'Length = Right'Length;
>>
>> Next (Next'First + 1 .. Next'Last - 1) :=
>> Next (Next'First .. Next'Last - 2) +
>> Next (Next'First + 2 .. Next'Last);
>
> OK, one can do this, but is it better than Nasser's?
>
>> for i in 2..next'length-1 loop
>> next(i):= now(i-1)+now(i+1);
>> end loop;
That's a different question, and depends on the definition of "better".
Using 'Length rather than 'Last is probably not a good idea for defining an
index into an array.
If the problem domain has lots of these partial-array operations, then defining
and using such operators might be more readable. If not, explicit loops might be
better. If these arrays are very large and space or time are tight, one might
need to concern oneself with low-level questions such as whether using an array
operator results in a temporary result and extra copy.
--
Jeff Carter
"I would never want to belong to any club that
would have someone like me for a member."
Annie Hall
41
prev parent reply other threads:[~2014-07-13 21:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-13 3:34 basic question on adding 2 arrays Nasser M. Abbasi
2014-07-13 4:09 ` Nasser M. Abbasi
2014-07-13 4:35 ` Nasser M. Abbasi
2014-07-13 6:33 ` Jeffrey Carter
2014-07-13 10:10 ` AdaMagica
2014-07-13 16:25 ` Jacob Sparre Andersen
2014-07-13 21:53 ` Jeffrey Carter [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox