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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.36.54.136 with SMTP id l130mr2955173itl.22.1512083593124; Thu, 30 Nov 2017 15:13:13 -0800 (PST) X-Received: by 10.157.81.193 with SMTP id d1mr215170oth.13.1512083593053; Thu, 30 Nov 2017 15:13:13 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.kjsl.com!usenet.stanford.edu!193no215440itr.0!news-out.google.com!193ni289iti.0!nntp.google.com!193no215435itr.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 30 Nov 2017 15:13:12 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=97.117.255.82; posting-account=x5rpZwoAAABMN2XPwcebPWPkebpwQNJG NNTP-Posting-Host: 97.117.255.82 References: <0b6bd27e-e9ec-4854-bbb1-85e1d9ac92e1@googlegroups.com> <227d5a7f-6d5b-4b76-ac31-7d15bb6dc284@googlegroups.com> <16c980c2-1fa6-4084-97ea-b576c75b99c3@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <304b7ec5-7d43-4fb3-9a61-d92cf4ea6b8e@googlegroups.com> Subject: Re: How to access an array using two different indexing schemes From: Jerry Injection-Date: Thu, 30 Nov 2017 23:13:13 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader02.eternal-september.org comp.lang.ada:49288 Date: 2017-11-30T15:13:12-08:00 List-Id: On Thursday, November 30, 2017 at 2:50:31 PM UTC-7, Randy Brukardt wrote: > > The only thing that does work is the type conversion in parameter passing > (as I originally illustrated). So something like the following should work > (should because I didn't try it): > The type conversion at the subroutine level also works for an open array in the formal argument. The following uses an array which is accessed by an access variable--the "usual" declaration method also works, i.e,. if x is declared as x : Real_Vector(-4 .. 3); with Ada.Text_IO; use Ada.Text_IO; with Ada.Numerics.Long_Real_Arrays; use Ada.Numerics.Long_Real_Arrays; procedure Randy_V3 is type Real_Vector_Access is access Real_Vector; x_Ptr : Real_Vector_Access := new Real_Vector(-4 .. 3); x : Real_Vector renames x_Ptr.all; subtype RV0_7 is Real_Vector(0..7); procedure Do_X(x : in out Real_Vector) is begin for i in x'range loop x(i) := x(i) + 0.1; Put_Line(i'img & " " & x(i)'img); end loop; end Do_X; procedure Do_Y(y : in out RV0_7) is begin for i in y'range loop y(i) := y(i) + 0.2; Put_Line(i'img & " " & y(i)'img); end loop; end Do_Y; procedure Do_Y_Open(y : in out Real_Vector) is begin for i in y'range loop y(i) := y(i) + 0.3; Put_Line(i'img & " " & y(i)'img); end loop; end Do_Y_Open; begin x := (-4.0, -3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0); Do_X(x); New_Line; Do_Y(RV0_7(x)); New_Line; Do_Y_Open(RV0_7(x)); end Randy_V3; -4 -3.90000000000000E+00 -3 -2.90000000000000E+00 -2 -1.90000000000000E+00 -1 -9.00000000000000E-01 0 1.00000000000000E-01 1 1.10000000000000E+00 2 2.10000000000000E+00 3 3.10000000000000E+00 0 -3.70000000000000E+00 1 -2.70000000000000E+00 2 -1.70000000000000E+00 3 -7.00000000000000E-01 4 3.00000000000000E-01 5 1.30000000000000E+00 6 2.30000000000000E+00 7 3.30000000000000E+00 0 -3.40000000000000E+00 1 -2.40000000000000E+00 2 -1.40000000000000E+00 3 -4.00000000000000E-01 4 6.00000000000000E-01 5 1.60000000000000E+00 6 2.60000000000000E+00 7 3.60000000000000E+00 Jerry