Sujet : How can I make Reduce run from right to left? De : b.mcguinness747 (at) *nospam* gmail.com (Brian9000) Groupes :comp.lang.ada Date : 10. Dec 2024, 18:20:53 Autres entêtes Organisation : novaBBS Message-ID :<aa2e9cf6fcb092ba4e227a41b05ae707@www.novabbs.com> User-Agent : Rocksolid Light
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