comp.lang.ada
 help / color / mirror / Atom feed
From: Chris Papademetrious <st92j0gw@post.drexel.edu>
Subject: Adding a "Project Types" layer to a project
Date: 1996/05/01
Date: 1996-05-01T00:00:00+00:00	[thread overview]
Message-ID: <3186E51C.250@post.drexel.edu> (raw)


I'm beginning a large project, and I'd like to base the entire project off base types defined in a package, as an extra layer of indirection for which I can 
change the underlying functionality later.  The problem is, I'm having problems adding this level of indirection.  Keep in mind I know very little about Ada 95, 
save for what I'm picking up here on the newsgroups and such...

 Here's what I have so far.  Note that I want everything in the project to use ONLY the types defined in the package "types", which I can change to affect the 
entire project.  This is the result I get when I try to compile this testcase:

/home/chrispy/bot > gnatmake test
gcc -c test.adb
test.adb:20:20: invalid operand types for operator "+"
gnatmake: *** compilation failed.

 If I use the type from the package "vectors" directly, it works.  If I create a subtype in types, and then use that, it fails.  What am I missing?  Thanks in 
advance...

 - Chris


===== vectors.ads:
package VECTORS is
  type VECTOR is array(integer range<>) of float ;

  function "+" (A : VECTOR; B : VECTOR) return VECTOR ; -- sum of vector
end VECTORS;

===== vectors.adb:
package body VECTORS is
  function "+" (A : VECTOR; B : VECTOR) return VECTOR is
    C : VECTOR(A'first..A'last) ;
  begin
    if A'first /= B'first or A'last /= B'last then
      raise INCOMPARABLE_DIMENSION;
    end if ;
    for I in A'range loop
      C(I) := A(I)+B(I) ;
    end loop ;
    return C ;
  end "+";
end VECTORS;

===== types.ads:
with Vectors;

package TYPES is
  subtype Distance is FLOAT;
  subtype Vector is Vectors.VECTOR;
end TYPES;


===== test.adb:
with Text_IO, Ada.Float_Text_IO, Ada.Integer_Text_IO;
with Types;

use Text_IO, Ada.Float_Text_IO, Ada.Integer_Text_IO;
use Types;

procedure test is

distance1: Distance := 2.0;
distance2: Distance := 3.0;
point1: Vector := (1.1, 2.2);
point2: Vector := (3.3, 4.4);

begin
  distance1 := distance1 + distance2;
  point1 := point1 + point2;
end;




             reply	other threads:[~1996-05-01  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-05-01  0:00 Chris Papademetrious [this message]
1996-05-01  0:00 ` Adding a "Project Types" layer to a project Robert A Duff
1996-05-01  0:00 ` John English
1996-05-02  0:00 ` Chad Bremmon
1996-05-06  0:00   ` Chris Papademetrious
replies disabled

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