comp.lang.ada
 help / color / mirror / Atom feed
* Re: Adding a "Project Types" layer to a project
  1996-05-01  0:00 Adding a "Project Types" layer to a project Chris Papademetrious
  1996-05-01  0:00 ` Robert A Duff
@ 1996-05-01  0:00 ` John English
  1996-05-02  0:00 ` Chad Bremmon
  2 siblings, 0 replies; 5+ messages in thread
From: John English @ 1996-05-01  0:00 UTC (permalink / raw)



Chris Papademetrious (st92j0gw@post.drexel.edu) wrote:
: /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...

You'll have to provide a renaming of "+" in Types, or "with Vectors" and
"use [type] Vectors" in the main program.  "+" is in Vectors but not in
Types, so the program doesn't know anything about it.

-- 
----------------------------------------------------------------------------
John English <je@brighton.ac.uk>, Dept. of Computing, University of Brighton
  "Disks are divided into sex and tractors..."
----------------------------------------------------------------------------




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

* Adding a "Project Types" layer to a project
@ 1996-05-01  0:00 Chris Papademetrious
  1996-05-01  0:00 ` Robert A Duff
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Chris Papademetrious @ 1996-05-01  0:00 UTC (permalink / 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;




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

* Re: Adding a "Project Types" layer to a project
  1996-05-01  0:00 Adding a "Project Types" layer to a project Chris Papademetrious
@ 1996-05-01  0:00 ` Robert A Duff
  1996-05-01  0:00 ` John English
  1996-05-02  0:00 ` Chad Bremmon
  2 siblings, 0 replies; 5+ messages in thread
From: Robert A Duff @ 1996-05-01  0:00 UTC (permalink / raw)



In article <3186E51C.250@post.drexel.edu>,
Chris Papademetrious  <st92j0gw@post.drexel.edu> wrote:
> 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...

There is no "+" declared in package Types.  Hence the error message.
The "+" you want to call is declared in Vectors, and it has to be
directly visible in order to call it.

You could rename the "+" operator into Types.

Or, you could say "use type Vector;" in Test.

Or, you could use a derived type instead of a subtype.  This will create
a new type, with an inherited "+", which may or may not be what you
want.

- Bob

P.S. I don't particularly like the idea of having a Types package, which
is just a big jumble of totally unrelated stuff.




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

* Re: Adding a "Project Types" layer to a project
  1996-05-01  0:00 Adding a "Project Types" layer to a project Chris Papademetrious
  1996-05-01  0:00 ` Robert A Duff
  1996-05-01  0:00 ` John English
@ 1996-05-02  0:00 ` Chad Bremmon
  1996-05-06  0:00   ` Chris Papademetrious
  2 siblings, 1 reply; 5+ messages in thread
From: Chad Bremmon @ 1996-05-02  0:00 UTC (permalink / raw)



Chris Papademetrious wrote:
> 
> 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...
> I would hesitate a bit to base everything on a "base types" package.  Although it seems like a good 
idea at first, when you are in the small scale, as the project gets larger, the initially simple 
types package gets more and more difficult to manage. 

We have to keep in mind the "object oriented way."  Supposedly, the data and the function are 
together.  What you have shown with your software problem is that by taking the vector functions and 
putting them in another package, they are not available when you use the vector type later on.  If 
you are using vectors, use the vectors package.  The indirection provided by the types package seems 
to confuse the problem.

I'm not saying that a "standard" types package is not a good thing.  There are times when it may 
make more sense that you might consider using a types package.  In those instances, you may consider 
limiting the types package to be within the subsystem you are using.  

cb




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

* Re: Adding a "Project Types" layer to a project
  1996-05-02  0:00 ` Chad Bremmon
@ 1996-05-06  0:00   ` Chris Papademetrious
  0 siblings, 0 replies; 5+ messages in thread
From: Chris Papademetrious @ 1996-05-06  0:00 UTC (permalink / raw)



 Thank you everyone for your replies!

 I think I was a bit over-eager to use this "project types" concept.
Chad is definitely right, for the project I'm working on, it's better
to just use the vectors package if I need vectors functionality.  I
was trying to offer as much flexibility and indirection as I could for
the groundwork, but it appears to be superfluous now that I look at
this instance.

 - Chris

Chad Bremmon <chad.bremmon@comm.hq.af.mil> wrote:
>We have to keep in mind the "object oriented way."  Supposedly, the data and the function are 
>together.  What you have shown with your software problem is that by taking the vector functions and 
>putting them in another package, they are not available when you use the vector type later on.  If 
>you are using vectors, use the vectors package.  The indirection provided by the types package seems 
>to confuse the problem.

>I'm not saying that a "standard" types package is not a good thing.  There are times when it may 
>make more sense that you might consider using a types package.  In those instances, you may consider 
>limiting the types package to be within the subsystem you are using.  

>cb






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

end of thread, other threads:[~1996-05-06  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-05-01  0:00 Adding a "Project Types" layer to a project Chris Papademetrious
1996-05-01  0:00 ` Robert A Duff
1996-05-01  0:00 ` John English
1996-05-02  0:00 ` Chad Bremmon
1996-05-06  0:00   ` Chris Papademetrious

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