From: b.mcguinness747@gmail.com (Brian9000)
Subject: How can I make Reduce run from right to left?
Date: Tue, 10 Dec 2024 17:20:53 +0000 [thread overview]
Message-ID: <aa2e9cf6fcb092ba4e227a41b05ae707@www.novabbs.com> (raw)
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
next reply other threads:[~2024-12-10 17:20 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-10 17:20 Brian9000 [this message]
2024-12-10 17:54 ` How can I make Reduce run from right to left? J-P. Rosen
2024-12-10 17:57 ` J-P. Rosen
2024-12-10 21:04 ` Jeffrey R.Carter
2024-12-11 0:15 ` Brian9000
2024-12-11 1:38 ` Brian9000
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox