[comp.lang.ada] What's wrong with this picture?

gicca@mervax.UUCP (Greg) (10/21/88)

What's wrong with this picture.  The below package Data does not compile.  
It looks fine to me, but there must be something I'm missing.  Does 
anyone see what I've overlooked.  The with'd source, Data package, error 
listing and generic are all listed below.

From my understanding, the LRM says the code is correct.   LRM section 
12.3.2(3) last statement, says:

  "(If, on the other hand, the formal type has no discriminants, the 
    actual type is allowed to have discriminants.)"

Thanks in advance for any help,


Greg Gicca
Sanders Associates
Nashua, N.H.
    
--:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
--Dynamic_String_Definition_.Ada
--:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
package Dynamic_String_Definition is

   type Dynamic_String(Maximum_Length : Positive) is
      record
         Value  : String(1..Maximum_Length);
         Length : Natural := 0;
      end record;

end Dynamic_String_Definition;
--:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
--Single_List_Utility_.Ada
--:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
generic
   type Element_Type is private;
package Single_List_Utility is

   type List_Type is private;

   .........

end Single_List_Utility;
--:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
--Data.Ada
--:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
with Single_List_Utility;
with Dynamic_String_Definition;
use  Dynamic_String_Definition;

package Data is new Single_List_Utility(Element_Type => 
   Dynamic_String(Maximum_Length => 132) );

--:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
--Compiler.Errors
--:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Data     19-Oct-1988 13:31:50    VAX Ada V1.4-33                     Page   1
01       19-Oct-1988 13:22:31    DATA_.ADA;1                              (1)

    1 	with Single_List_Utility;
    2 	with Dynamic_String_Definition;
    3 	use  Dynamic_String_Definition;
    4 	
    5 	package Data is new Single_List_Utility(Element_Type => 
    6 	   Dynamic_String(Maximum_Length => 132) );
...........1.............2...............3
(3) A named association is not a form of expression [LRM 4.4(2)]
(2) A type conversion is not a form of name [LRM 4.1(2)]
(1)     For Dynamic_String the meaning is record type Dynamic_String in 
        Dynamic_String_Definition at line 3
(2) Error occurs in actual corresponding to generic formal type Element_Type 
        in Single_List_Utility at line 2
------------------------------------------------------------------------------

ark@ritcv.UUCP (Alan Kaminsky) (10/24/88)

> What's wrong with this picture.  The below package Data does not compile.  
> It looks fine to me, but there must be something I'm missing.  Does 
> anyone see what I've overlooked.  The with'd source, Data package, error 
> listing and generic are all listed below.
> . . .
> --:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
> --Data.Ada
> --:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
> with Single_List_Utility;
> with Dynamic_String_Definition;
> use  Dynamic_String_Definition;
> 
> package Data is new Single_List_Utility(Element_Type => 
>    Dynamic_String(Maximum_Length => 132) );

Summarizing the original posting:  We are trying to instantiate a generic
package, Single_List_Utility, which has a single generic formal parameter,
Element_Type, that was declared to be a private type.  In the instantiation,
we are trying to match this generic formal parameter with an actual type,
Dynamic_String, that has a discriminant, Maximum_Length.  We are trying to
supply a value for the discriminant as we instantiate the generic package.
The goal is to instantiate a version of Single_List_Utility that works on
Dynamic_Strings of length 132.  The compiler does not like this generic
instantiation.

The problem is simply one of Ada syntax.  A generic_actual_parameter must
be a type_mark [ALRM 12.3] if the actual parameter is a data type.  A
type_mark must be a type_name or subtype_name [ALRM 3.3.2].  Thus, the
generic actual parameter must be simply a name, not a name followed by a
discriminant.

Here is how to get what we want:

	with Single_List_Utility;
	with Dynamic_String_Definition;
	use  Dynamic_String_Definition;
	
	subtype String_132 is Dynamic_String (Maximum_Length => 132);

	package Data is new Single_List_Utility
		(Element_Type => String_132);

-- 
Alan Kaminsky                           P. O. Box 9887
School of Computer Science              Rochester, NY  14623
Rochester Institute of Technology       716-475-5255
ark@cs.rit.edu