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,bf03d731a6ef511f X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!v20g2000prb.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Copying rows in a two dimensional array. Date: Tue, 2 Feb 2010 17:24:06 -0800 (PST) Organization: http://groups.google.com Message-ID: <9f57a71f-4011-4cc2-a180-eac81978127e@v20g2000prb.googlegroups.com> References: <4b6637a1$0$4586$4d3efbfe@news.sover.net> <62eb2ccd-b3ff-4a8a-ab80-21c5bb0a0ef4@k18g2000prf.googlegroups.com> 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 1265160247 31407 127.0.0.1 (3 Feb 2010 01:24:07 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 3 Feb 2010 01:24:07 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: v20g2000prb.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),gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:8866 Date: 2010-02-02T17:24:06-08:00 List-Id: On Feb 2, 2:23=A0pm, Jerry wrote: > On Feb 2, 1:52=A0am, Jean-Pierre Rosen wrote: > > > > > > > Jerry a =E9crit :> I've never understood why Ada does not allow slicing= in > > > multidimensional arrays. What are the safety issues involved? And how > > > is it safe to force the programmer into ad hoc methods? > > > One-dimensional slices are simple and efficient. Multidimensional slice= s > > are a can of worms. > Well, yes, I was thinking of rectangular slices. No doubt the (cost of > implementation) / usefulness is high (and usage difficult) for non- > rectangular parts, but that is far less common than rectangular parts. > Python, Matlab/Octave, Igor Pro... all pull it off without too much > hassle (although Python asks you to imagine addressing the array by > the "cracks" between elements, as I recall--probably a disease of C- > style counting). I don't know anything about any of those languages. What I know about Ada is that when multi-dimensional arrays are passed as parameters to procedures, they're normally passed by reference (if they're large enough). Some arrays are required to be passed by reference; in other cases, it's unspecified, but I'd expect any array to be passed by reference unless it's a packed array of 32 Booleans or something. So say you have a procedure: type Matrix is array (Natural range <>, Natural range <>) of Float; procedure Operation_On_Matrix (M : in out Matrix) is ... You later declare a matrix: X : Matrix (1..10, 1..10); and want to call the operation on a rectangular slice. If the "slice" consists of an entire row, or one or more consecutive rows: Operation_On_Matrix (X (3..4, 1..10)); this could be done as efficiently as if all of X were passed, since the procedure would see it as an array of 20 consecutive floats (in a typical implementation). However, a slice consisting of one or more columns: Operation_On_Matrix (X (1..10, 5..6)); or some smaller rectangle: Operation_On_Matrix (X (4..6, 4..6)); would be tricky, since the procedure now has to be told that there are gaps between the "rows" of the array that it's seeing as a parameter. This means making Operation_On_Matrix less efficient, since it has to be given more information about each Matrix that comes in; and the inefficiency has to be put there even if no caller ever used a 2-D rectangular slice, ever. Maybe the efficiency hit isn't all that large---I don't know. It wouldn't really work to fix the language to say that rectangular slices are allowed only if they include the entire index range in all dimensions but the first, since that would fail for array types declared with the Fortran convention. I realize that the original question was about using assignment to copy slices. I suppose that, theoretically, the language could be changed to allow multi-dimensional slices in assignments but not as subprogram parameters. Yuck. I wouldn't want to add that kind of inconsistency to the language. Anyway, I don't know how serious these issues are, but this seems to me to be a possible reason why adding this feature isn't as simple as it sounds. -- Adam