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: 103376,32d9aa9d79729b31 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.219.170 with SMTP id pp10mr10628928pbc.1.1341514599585; Thu, 05 Jul 2012 11:56:39 -0700 (PDT) Path: l9ni10941pbj.0!nntp.google.com!news2.google.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Any easy/build-in construct to extract submatrices from larger matrix? Date: Thu, 5 Jul 2012 11:56:38 -0700 (PDT) Organization: http://groups.google.com Message-ID: <9b4da1cf-ca48-4b0b-97e5-012bf786a3e0@googlegroups.com> References: <788af57d-750d-418d-94bb-75c6557e36a9@g4g2000pbn.googlegroups.com> <3f8db781-fd78-4505-837d-1811c0f9b96f@googlegroups.com> <18bqgllh2jdwg$.upj6crleq9nv$.dlg@40tude.net> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 X-Trace: posting.google.com 1341514599 1578 127.0.0.1 (5 Jul 2012 18:56:39 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 5 Jul 2012 18:56:39 +0000 (UTC) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-07-05T11:56:38-07:00 List-Id: On Wednesday, July 4, 2012 6:33:32 PM UTC-7, Randy Brukardt wrote: > > Again, compared to what? >=20 > Compared to a language without 2-d slices. >=20 > This is distributed overhead, which programs would have to pay whether o= r=20 > not they used any 2-d slices. It would make all array parameters more=20 > expensive. Distributed overhead is only acceptable in cases where there i= s a=20 > clear and important value to the new feature. It seems to me that the "generalized indexing" syntax of Ada 2012 could be = used to write a package to support this functionality. I think you could w= rite a generic package that defines a 2-D array of an element type, but def= ines it as a tagged record that (internally) points to the array storage. = The package would define First, Last, Length functions for the type that ta= ke a dimension parameter. It could also define a Slice function that would= return a new 2-D array with the new bounds, but pointing to the same stora= ge. The new syntax would allow programmers to index the array in the same = way they would now. Of course, not all the syntax would be equivalent, and= some would require extra typing; you'd have to say something like for I in Arr.First(1) .. Arr.Last(1) loop instead of for I in Arr'Range(1) I haven't studied all the details. But off the top of my head, I think thi= s could be made to work, and probably could be implemented with only a slig= ht amount of overhead compared to if it were built into the language. Sinc= e 2-D slices aren't a feature I'd expect to be used widely, this seems like= a better approach than adding it to the language and incurring distributed= overhead (on top of all the other overhead required to change all existing= Ada implementations without breaking them, and making changes to the stand= ard). -- Adam