DocAda(tm) is a productivity tool of KSCE

Prev | Up | Next | Back | Forward
About DocAda Light: Preface / Preliminary / Help / TOC / Copyright
DocAda Online at the Ada Home: Complete RM95 / Updates / News

12.6 Formal Subprograms

Formal subprograms can be used to pass callable entities to a generic unit.

Syntax

   
       formal_subprogram_declaration ::= with subprogram_specification [is subprogram_default];

       subprogram_default ::= default_name | <>

       default_name ::= name

Name Resolution Rules

The expected profile for the default_name, if any, is that of the formal subprogram.

For a generic formal subprogram, the expected profile for the actual is that of the formal subprogram.

Legality Rules

The profiles of the formal and any named default shall be mode-conformant.

The profiles of the formal and actual shall be mode-conformant.

Static Semantics

A formal_subprogram_declaration declares a generic formal subprogram. The types of the formal parameters and result, if any, of the formal subprogram are those determined by the subtype_marks given in the formal_subprogram_declaration; however, independent of the particular subtypes that are denoted by the subtype_marks, the nominal subtypes of the formal parameters and result, if any, are defined to be nonstatic, and unconstrained if of an array type (no applicable index constraint is provided in a call on a formal subprogram). In an instance, a formal_subprogram_declaration declares a view of the actual. The profile of this view takes its subtypes and calling convention from the original profile of the actual entity, while taking the formal parameter names and default_expressions from the profile given in the formal_subprogram_declaration. The view is a function or procedure, never an entry.

If a generic unit has a subprogram_default specified by a box, and the corresponding actual parameter is omitted, then it is equivalent to an explicit actual parameter that is a usage name identical to the defining name of the formal.

Examples

Examples of generic formal subprograms:

    
       with function "+"(X, Y : Item) return Item is <>;
       with function Image(X : Enum) return String is Enum'Image;
       with procedure Update is Default_Update;

       --  given the generic procedure declaration

       generic
          with procedure Action (X : in Item);
       procedure Iterate(Seq : in Item_Sequence);

       --  and the procedure

       procedure Put_Item(X : in Item);

       --  the following instantiation is possible

       procedure Put_List is new Iterate(Action => Put_Item);

About DocAda Light: Preface / Preliminary / Help / TOC / Copyright
DocAda Online at the Ada Home: Complete RM95 / Updates / News
Prev | Up | Next | Back | Forward


Copyright © 1994-1997 by Kempe Software Capital Enterprises. All Rights Reserved. For comments on this DocAda(tm) hypertext document, please write to KSCE, at docada@ksce.com