Sujet : Re: How can I make Reduce run from right to left? De : b.mcguinness747 (at) *nospam* gmail.com (Brian9000) Groupes :comp.lang.ada Date : 11. Dec 2024, 02:38:59 Autres entêtes Organisation : novaBBS Message-ID :<57349e0bb1125f359b96c743a706a087@www.novabbs.com> References :1 User-Agent : Rocksolid Light
I finally got an APL-like reduction using Ada Reduce: 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)]; function Minus (Accumulator : Real; Value : Real) return Real is (Value - Accumulator); 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 0 .. data'Last - 1 => data(data'Last - 1 - i) ]'Reduce(Minus, data(data'Last)))); end Reverse_Reduction; $ ./reverse_reduction 0: 1.00000000000000E+00 1: 2.00000000000000E+00 2: 3.00000000000000E+00 3: 4.00000000000000E+00 4: 5.00000000000000E+00 5: 6.00000000000000E+00 6: 7.00000000000000E+00 7: 8.00000000000000E+00 8: 9.00000000000000E+00 9: 1.00000000000000E+01 10: 1.10000000000000E+01 11: 1.20000000000000E+01 -6.00000000000000E+00 In Gnu APL: ⍳12 1 2 3 4 5 6 7 8 9 10 11 12 -/⍳12 ¯6 --- Brian