From mboxrd@z Thu Jan 1 00:00:00 1970 Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!news.building-m.net!news.quux.org!i2pn.org!i2pn2.org!.POSTED!not-for-mail From: b.mcguinness747@gmail.com (Brian9000) Newsgroups: comp.lang.ada Subject: How can I make Reduce run from right to =?UTF-8?B?bGVmdD8=?= Date: Tue, 10 Dec 2024 17:20:53 +0000 Organization: novaBBS Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: i2pn2.org; logging-data="2215015"; mail-complaints-to="usenet@i2pn2.org"; posting-account="9ajNdu7Big9oozdloDc82V1pJPCqMw0ldBK5SFX9VYw"; User-Agent: Rocksolid Light X-Rslight-Posting-User: e5304281a291c72cb8553ee6646030d84d2813e2 X-Rslight-Site: $2y$10$JVWs5HjHVgt4ltwWX7EzO.mIve4ZMnRxkuWfHGU2oJKUF6ikEgIPa X-Spam-Checker-Version: SpamAssassin 4.0.0 Xref: news.eternal-september.org comp.lang.ada:66482 List-Id: I am trying to find a way to make Reduce operate from right to left like APL reduction, but this doesn't seem to work. I wrote a test program: pragma Ada_2022; pragma Extensions_Allowed (On); with Ada.Text_IO; procedure Reverse_Reduction is type Real is digits 15; type Vector is array(Natural range <>) of Real; data : constant Vector := [for i in 0 .. 11 => Real (i + 1)]; begin for i in data'Range loop Ada.Text_IO.Put_Line (i'Image & ": " & data(i)'Image); end loop; Ada.Text_IO.New_Line; Ada.Text_IO.Put_Line (Real'Image ([ for i in 1 .. data'Last => data(i) ]'Reduce("-", data(0)))); Ada.Text_IO.Put_Line (Real'Image ([ for i in reverse 0 .. data'Last - 1 => data(i) ]'Reduce("-", data(data'Last)))); end Reverse_Reduction; but the compiler won't accept "reverse" in the next-to-last line, even though you can use it in a normal loop. The other lines compile and run without any problems. $ gnatmake reverse_reduction.adb x86_64-linux-gnu-gcc-12 -c reverse_reduction.adb reverse_reduction.adb:18:47: error: missing operand x86_64-linux-gnu-gnatmake-12: "reverse_reduction.adb" compilation error Of course I can just write a normal loop to do this, but I wanted to see if I could do it with Reduce. --- Brian