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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,19924f2facf8443 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Larger matrices Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <40ed91c2-3dab-4994-9a7b-4032058f0671@56g2000hsm.googlegroups.com> <4899b545$0$20713$9b4e6d93@newsspool4.arcor-online.net> <96f76821-fc2a-4ec1-83e7-b7b9a5be0520@r66g2000hsg.googlegroups.com> <9cabee20-877a-4fdc-80f8-7746879331da@8g2000hse.googlegroups.com> <489a9675$0$20718$9b4e6d93@newsspool4.arcor-online.net> <75a339dd-969b-4c7a-8e89-7b640171bc2f@e53g2000hsa.googlegroups.com> <13426f2d-0060-47f0-8139-09506383f648@e53g2000hsa.googlegroups.com> Date: Fri, 8 Aug 2008 12:38:09 +0200 Message-ID: <1nn9c93skd9lz$.1g5ogwfb9v6mp.dlg@40tude.net> NNTP-Posting-Date: 08 Aug 2008 12:38:09 CEST NNTP-Posting-Host: 73d9a15b.newsspool4.arcor-online.net X-Trace: DXC=S2SW;b1ibnA6PJ?[X6JIXE4IUK\BH3YBNHnmVf8:^]KDNcfSJ;bb[EFCTGGVUmh?DLK[5LiR>kgBfni1UcOY8UL X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:1535 Date: 2008-08-08T12:38:09+02:00 List-Id: On Fri, 8 Aug 2008 02:59:56 -0700 (PDT), amado.alves@gmail.com wrote: >>> And Ada got in the way: slicing restricted to one-dimensional arrays! >> >> Compared to other languages that have no slicing at all? > > There are languages better than Ada at array indexing, including > slicing. If there aren't, there should be! > > A bidimensional array like the standard Real_Matrix should be > compatible with a unidimensional array like Real_Vector. > One row (or one column) of a matrix is a vector. > In fact aggregate notation reflects this > > Matrix := ( (a, b, c) , > (d, e, f) , > (g, h, i) ); > > Vector := (x, y, x); > > but then the obvious are illegal: > > Vector := Matrix (1); -- (a, b, c) > > or > > Band_Matrix := Matrix (1 .. 2); -- ( (a, b, c) , > -- (d, e, f) ) > > A good language should even permit > > Vertical_Band_Matrix := Matrix (Matrix'Range, 1 .. 2); -- ( (a, b) , > (d, e) , > -- (g, h) ) > or > > Block := Matrix (1 .. 2, 1 .. 2); -- ( (a, b) , > -- (d, e) ) A good language should support keyed notation of array indices: Vector := Matrix (Column => 1); -- (a, d, g) type Matrix is array (Row, Column : Positive range <>) of Float; It also should provide index types: type Square is index (Row, Column : Positive range <>); type Matrix is array (Square) of Float; and type Matrix is array (Row, Column : Positive range <>) of Float; subtype Square is Matrix'Index; and iteration for I in M'Index loop -- Zeroes all matrix M (I) := 0.0; end loop; and enumeration case A'Index is when (1,1) | (2,2) => ... when others => ... end case; and array aggregates ((1,1)=>0.0, (1,2)=>...); -- Flat notation The value of an index type is a tuple. Elements of the tuple are ranges and individual indices. All operations you mentioned above are compositions of the corresponding slicing of the index type and then indexing the array by the index. The result of indexing depends on the index type: A (1, 2) -- Element, dimension 0 A (1..1, 2) -- Vector, dimension 1 A (1..1, 2..2) -- Matrix, dimension 2 There also has to be range types and range values. Last but not least, a good language should allow reasonable array renaming with bounds slicing. Array renaming in Ada is bogus. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de