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=unavailable autolearn_force=no version=3.4.4 Path: border2.nntp.dca1.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!feeder.erje.net!eu.feeder.erje.net!news2.arglkargh.de!newsfeed.fsmpi.rwth-aachen.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Jeffrey Carter Newsgroups: comp.lang.ada Subject: Re: basic question on adding 2 arrays Date: Sun, 13 Jul 2014 14:53:47 -0700 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <76d7dbf2-e6b8-4304-b90a-c29a5d129156@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 13 Jul 2014 21:53:49 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="ec00b5351686c67721798cbf9cd968b0"; logging-data="31544"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18mi8+Wn7uOtpv2Sjhp0Ornyw9/a+kki4M=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: <76d7dbf2-e6b8-4304-b90a-c29a5d129156@googlegroups.com> Cancel-Lock: sha1:3gMxoNpVuZzY9iTMSBR8TrJERC0= Xref: number.nntp.dca.giganews.com comp.lang.ada:187572 Date: 2014-07-13T14:53:47-07:00 List-Id: 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