comp.lang.ada
 help / color / mirror / Atom feed
* Re: Instantiation before body seen
  1998-01-09  0:00 Instantiation before body seen Dmitriy Anisimkov
@ 1998-01-08  0:00 ` Matthew Heaney
  1998-01-10  0:00   ` Dmitriy Anisimkov
  0 siblings, 1 reply; 3+ messages in thread
From: Matthew Heaney @ 1998-01-08  0:00 UTC (permalink / raw)



In article <01bd1c95$ddeacf60$LocalHost@---->, "Dmitriy Anisimkov"
<ts@quadrat.omsk.su> wrote:

>Compilation of my package by GNAT-3-10 
>
>--------------------------------
>package AnyPackage
> ..................
>private generic
>   with function Compare(C1,C2 : Comp) return Boolean;
>function Compare(R1,R2 : TRational) return Boolean;
>   
>function "<" is new Compare("<");
>function ">" is new Compare(">");
>function "<=" is new Compare("<=");
>function ">=" is new Compare(">=");
>function "=" is new Compare("=");
> ..................
>end AnyPackage
>----------------------
>
>causes warning
>'cannot instantiate "AnyMyFunction" before body seen'
>I have defined body later.
>
>Is there GNAT limitation or language limitation ?

Language "feature."  The specification of AnyPackage has to elaborate prior
to its body.  Therefore there's no way to instaniate Compare in the spec,
because its body is in the body of AnyPackage, which hasn't elaborated yet. 
What code would be "filled in" if you were able to instantiate Compare in
the spec, if the template from which that code derives doesn't "exist" yet?

What you can do is declare a function specification, and then use an
instantiation of Compare as the body of that declaration, via a renames
clause.  Something like:

package AnyPackage is

   function "=" (L, R : TRational) return Boolean;
...
end;

package body AnyPackage is

   generic
      ...
   function Compare (...) return Boolean;

   function Compare (...) return Boolean is ... end Compare;


   function Is_Equal is new Compare ("=");  -- recursive???

   function "=" (L, R : TRational) return Boolean renames Is_Equal;
...
end;

Note that even in the body of the package, the body of Compare must precede
any instantiations, or you'll get Program_Error.  GNAT is nicely warning
you in advance that that's what will happen.

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




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

* Instantiation before body seen
@ 1998-01-09  0:00 Dmitriy Anisimkov
  1998-01-08  0:00 ` Matthew Heaney
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitriy Anisimkov @ 1998-01-09  0:00 UTC (permalink / raw)



Compilation of my package by GNAT-3-10 

--------------------------------
package AnyPackage
 ..................
private generic
   with function Compare(C1,C2 : Comp) return Boolean;
function Compare(R1,R2 : TRational) return Boolean;
   
function "<" is new Compare("<");
function ">" is new Compare(">");
function "<=" is new Compare("<=");
function ">=" is new Compare(">=");
function "=" is new Compare("=");
 ..................
end AnyPackage
----------------------

causes warning
'cannot instantiate "AnyMyFunction" before body seen'
I have defined body later.

Is there GNAT limitation or language limitation ?






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

* Re: Instantiation before body seen
  1998-01-08  0:00 ` Matthew Heaney
@ 1998-01-10  0:00   ` Dmitriy Anisimkov
  0 siblings, 0 replies; 3+ messages in thread
From: Dmitriy Anisimkov @ 1998-01-10  0:00 UTC (permalink / raw)



Matthew Heaney <mheaney@ni.net> �������� � ������ <mheaney-

> package body AnyPackage is
>    generic
>    function Compare (...) return Boolean;
>    function Compare (...) return Boolean is ... end Compare;
>    function Is_Equal is new Compare ("=");  -- recursive???
>    function "=" (L, R : TRational) return Boolean renames Is_Equal;

Thank you Matthew,
it is that I want.




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

end of thread, other threads:[~1998-01-10  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-01-09  0:00 Instantiation before body seen Dmitriy Anisimkov
1998-01-08  0:00 ` Matthew Heaney
1998-01-10  0:00   ` Dmitriy Anisimkov

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