From mboxrd@z Thu Jan 1 00:00:00 1970 Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!i2pn.org!i2pn2.org!.POSTED!not-for-mail From: b.mcguinness747@gmail.com (Brian9000) Newsgroups: comp.lang.ada Subject: Re: How can I make Reduce run from right to =?UTF-8?B?bGVmdD8=?= Date: Wed, 11 Dec 2024 01:38:59 +0000 Organization: novaBBS Message-ID: <57349e0bb1125f359b96c743a706a087@www.novabbs.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: i2pn2.org; logging-data="2270579"; mail-complaints-to="usenet@i2pn2.org"; posting-account="9ajNdu7Big9oozdloDc82V1pJPCqMw0ldBK5SFX9VYw"; User-Agent: Rocksolid Light X-Spam-Checker-Version: SpamAssassin 4.0.0 X-Rslight-Posting-User: e5304281a291c72cb8553ee6646030d84d2813e2 X-Rslight-Site: $2y$10$0/2CN2o.Gi1R6SchzOufA.b9NUDyep/CGWSyMRbcRjBuba99pUfZS Xref: news.eternal-september.org comp.lang.ada:66489 List-Id: 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