comp.lang.ada
 help / color / mirror / Atom feed
* Problem instantiating "&" using GNAT
@ 1997-11-18  0:00 Doug Rogers
  0 siblings, 0 replies; only message in thread
From: Doug Rogers @ 1997-11-18  0:00 UTC (permalink / raw)



This is a multi-part message in MIME format.

--------------F9EF93051859A6F7328A4A7
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I've looked at this code quite a bit and can't see what I'm
doing wrong. I'm assuming that there's an error on my part
and not on the compiler, since I've only encountered a few
problems with GNAT, and they were all resolved many versions
ago.

I'm instantiating a generic matrix concatenation operation,
called "&" of course. Here's what GNAT gives:

  gnatmake fun
  gcc -c fun.adb
  fun.adb:8:04: instantiation error at fun_matrix.adb:30
  fun.adb:8:04: invalid operand types for operator "&"
  gnatmake: "fun.adb" compilation error

The code is attached. Any help would be appreciated.

Doug
--_._-__-____------_--_-_-_-___-___-____-_--_-___--____-___--_-__--___-_
Doug Rogers, ICI   | And a statute which either forbids or requires
V:703.893.2007x220 | the doing of an act in terms so vague that men of
F:703.893.5890     | common intelligence must necessarily guess at its
___________________| meaning and differ as to its application,
 violates the first essential of due process of law. [Connally v.
General Construction, 269 USC 385 (1926)]

--------------F9EF93051859A6F7328A4A7
Content-Type: text/plain; charset=us-ascii; name="all.adb"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="all.adb"

generic
   type Real is digits <>; -- private;
   type Index is range <>;
   type Vector is array (Index range <>) of Real;
   type Matrix is array (Index range <>, Index range <>) of Real;
package Fun_Matrix is
   function  Row (M : Matrix; I : Index) return Vector;
   procedure Set_Row (M : out Matrix; I : in Index; To : in Vector);

   -- --------------------------------------------------------------------
   -- "&":
   --  Concatenates two matrices into upper left and lower right corners
   --  of the returned matrix.
   --
   function  "&" (M1, M2 : Matrix) return Matrix;
end Fun_Matrix;
package body Fun_Matrix is
   function Row (M : Matrix; I : Index) return Vector is
      V : Vector (M'range(2));
   begin 
      for J in V'range loop
         V(J) := M(I,J);
      end loop;
      return V;
   end Row;
   
   procedure Set_Row (M : out Matrix; I : in Index; To : in Vector) is
   begin 
      for J in To'range loop
         M(I,M'first(2) + J - To'first) := To(J);
      end loop;
   end Set_Row;
   
   -- --------------------------------------------------------------------
   -- "&":
   --  Concatenates two matrices into upper left and lower right corners
   --  of the returned matrix.
   --
   function "&" (M1, M2 : Matrix) return Matrix is
      Result : Matrix (Index'first .. Index'first + M1'length(1) + M2'length(1) - 1,
                       Index'first .. Index'first + M1'length(2) + M2'length(2) - 1); -- := (others => (others => 0.0));
      Zero1  : constant Vector (M1'range(2)) := (others => 0.0);
      Zero2  : constant Vector (M2'range(2)) := (others => 0.0);
   begin
      for I in M1'range(1) loop
         Set_Row (Result, Result'first + I - M1'first(1), To => Row (M1, I) & Zero2);
      end loop;
      for I in M2'range(1) loop
         Set_Row (Result, Result'first + M1'length(1) + I - M2'first(1), To => Zero1 & Row (M2, I));
      end loop;
      return Result;
   end "&";

end Fun_Matrix;
with Fun_Matrix;

procedure Fun is
   type Real is digits 15;
   type Vector is array (Positive range <>) of Real;
   type Matrix is array (Positive range <>, Positive range <>) of Real;
   
   package Math is new Fun_Matrix (Real, Positive, Vector, Matrix);
   use Math;
begin
   null;
end Fun;

--------------F9EF93051859A6F7328A4A7--





^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1997-11-18  0:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-11-18  0:00 Problem instantiating "&" using GNAT Doug Rogers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox