comp.lang.ada
 help / color / mirror / Atom feed
From: "Matthew Heaney" <matthew_heaney@acm.org>
Subject: Re: Generic package array parameter
Date: 1999/11/12
Date: 1999-11-12T00:00:00+00:00	[thread overview]
Message-ID: <382c7b29_1@news1.prserv.net> (raw)
In-Reply-To: Pine.LNX.4.10.9911121752180.11396-100000@lexis.di.fct.unl.pt

In article 
<Pine.LNX.4.10.9911121752180.11396-100000@lexis.di.fct.unl.pt> , Mario
Amado Alves <maa@di.fct.unl.pt>  wrote:

> generic
>   type X is (<>);
>   type Y is (<>);
>   type Table_Type is array(X, Y) of X;
>   Table: Table_Type;
> package Foo is
> ...
>
> which of course works, but is odd, and requires an equally odd
> instantiation:
>
> type My_X is ...;
> type My_Y is ...;
> type My_Table_Type is array(My_X, My_Y) of My_X;
> My_Table: My_Table_Type := (...);
> package My_Foo is new Foo(My_X, My_Y, My_Table_Type, My_Table);
> ...


There is nothing odd about this instantiation.  The only thing odd here
is that you would find it odd!

Your generic formal region has 3 formal types and 1 formal object, and
you supply 3 actual types and 1 actual object.  What else did you expect
you'd have to do?

If you call a subprogram that has 4 formal parameters, then you expect
to call it with 4 actual parameters.  What else is new?


> This works, but is ugly and stupid.

I'm sorry to hear that.


> Is there a smart way to rewrite it?

Do you need to import the type and the object as generic formals?

generic
  type XT is (<>);
  type YT is (<>);
  type ZT is private;
package GP is

  type Array_Type is array (XT, YT) of ZT;

  Table : Array_Type;
...
end GP;


Do you need to import index types?  What's wrong with Positive?

generic
  type ZT is private;
  Max_X : in Positive;
  Max_Y : in Positive;
package GP is

  type Array_Type is array (Positive range <>, Positive range <>) of ZT;

  Table : Array_Type (1 .. Max_X, 1 .. Max_Y);
...
end GP;

If named access types offend you, then just declare your table with an
anonymous type:

generic
  ...
package GP is

  Table : array (1 .. Max_X, 1 .. Max_Y) of ZT;

end GP;


> (I feel I am again on the verge of giving up the Ada generic programming
> idiom. What is this Ada thing with anonymous array types?)

Don't criticize what you don't understand.

(Anonymous array types aren't allowed because, what would "=" mean for
the type?  What would ":=" mean for the type?

  function (L, R : ???) return Boolean;

What's the type of the formal parameters of function "="?

  procedure ":=" (L : in out ???; R : in ???);

What are the types on the LHS and on the RHS?

Operations are always associated with a type.  The type needs a name in
order to associate an operation with the type.  But if the array is
anonymous, then you don't have a name, so you don't have the operation
either...)


--
Science is, foremost, a method of interrogating reality: proposing
hypotheses that seem true and then testing them -- trying, almost
perversely, to negate them, elevating only the handful that survive to
the status of a theory. Creationism is a doctrine, whose adherents are
interested only in seeking out data that support it.

George Johnson, NY Times, 15 Aug 1999




  parent reply	other threads:[~1999-11-12  0:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-11-04  0:00 HELP - MAC compilation of an Ada program William A Whitaker
1999-11-05  0:00 ` James E. Hopper
1999-11-05  0:00 ` Robert Dewar
1999-11-12  0:00 ` Generic package array parameter Mario Amado Alves
1999-11-12  0:00   ` Tucker Taft
1999-11-12  0:00   ` Matthew Heaney [this message]
1999-11-13  0:00     ` Robert A Duff
1999-11-23  0:00       ` Mario Amado Alves
1999-11-23  0:00         ` Matthew Heaney
replies disabled

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