comp.lang.ada
 help / color / mirror / Atom feed
* What am I missing here?
@ 1997-11-18  0:00 Anonymous
  1997-11-18  0:00 ` Tucker Taft
  0 siblings, 1 reply; 2+ messages in thread
From: Anonymous @ 1997-11-18  0:00 UTC (permalink / raw)



The following code has a compilation error (distilled from a much larger
real-world system):

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);
                                  --^ Error here *****
      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;

The error message is

invalid operand types for operator "&"

This error does not occur if the order of the operands is reversed, nor
if the package is not generic (it is labeled an "instantiation error",
so that's not surprising). Any assistance would be greatly appreciated.

Jeff Carter  PGP:1024/440FBE21
My real e-mail address: ( carter @ innocon . com )
"You empty-headed animal-food-trough wiper."
Monty Python & the Holy Grail

Posted with Spam Hater - see
http://www.compulink.co.uk/~net-services/spam/




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: What am I missing here?
  1997-11-18  0:00 What am I missing here? Anonymous
@ 1997-11-18  0:00 ` Tucker Taft
  0 siblings, 0 replies; 2+ messages in thread
From: Tucker Taft @ 1997-11-18  0:00 UTC (permalink / raw)



Anonymous (nobody@REPLAY.COM) wrote:
: The following code has a compilation error (distilled from a much larger
: real-world system):

: ...

: The error message is

: invalid operand types for operator "&"

: This error does not occur if the order of the operands is reversed, nor
: if the package is not generic (it is labeled an "instantiation error",
: so that's not surprising). Any assistance would be greatly appreciated.

This seems to be a compiler bug.  I can't find anything
wrong with your code (nor can my favorite Ada 95 front end).

: Jeff Carter  PGP:1024/440FBE21
: My real e-mail address: ( carter @ innocon . com )
: "You empty-headed animal-food-trough wiper."
: Monty Python & the Holy Grail

: Posted with Spam Hater - see
: http://www.compulink.co.uk/~net-services/spam/

--
-Tucker Taft   stt@inmet.com   http://www.inmet.com/~stt/
Intermetrics, Inc.  Burlington, MA  USA




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1997-11-18  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-11-18  0:00 What am I missing here? Anonymous
1997-11-18  0:00 ` Tucker Taft

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