Prev | Up | Next | Back | Forward
TOC -- / --.-- / --.--.-- | Index | Search | Syntax | Help


12.6 Formal Subprograms

(1)
Formal subprograms can be used to pass callable entities to a generic unit.
Syntax
(2)
       formal_subprogram_declaration ::= with subprogram_specification [is subprogram_default];
(3)
       subprogram_default ::= default_name | <>
(4)
       default_name ::= name
Name Resolution Rules
(5)
The expected profile for the default_name, if any, is that of the formal subprogram.
(6)
For a generic formal subprogram, the expected profile for the actual is that of the formal subprogram.
Legality Rules
(7)
The profiles of the formal and any named default shall be mode-conformant.
(8)
The profiles of the formal and actual shall be mode-conformant.
Static Semantics
(9)
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.
(10)
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.

(11)
(12)
(13)
(14)
(15)
(16)
Examples
(17)
Examples of generic formal subprograms:
(18)
       with function "+"(X, Y : Item) return Item is <>;
       with function Image(X : Enum) return String is Enum'Image;
       with procedure Update is Default_Update;
(19)
       --  given the generic procedure declaration
(20)
       generic
          with procedure Action (X : in Item);
       procedure Iterate(Seq : in Item_Sequence);
(21)
       --  and the procedure
(22)
       procedure Put_Item(X : in Item);
(23)
       --  the following instantiation is possible
(24)
       procedure Put_List is new Iterate(Action => Put_Item);


Prev | Up | Next | Back | Forward
TOC -- / --.-- / --.--.-- | Index | Search | Syntax | Help

Ada WWW Home -- Email comments, additions, corrections, gripes, kudos, etc. to:

Magnus Kempe -- Magnus.Kempe@di.epfl.ch
Copyright statement
Page last generated: 95-03-12