Parameters That Are Subprogram Names

Type Checking
Pascal:
e.g.  (pages 357 to 358)
procedure integrate(function fun(x : real) : real;    -----> Both real are formal parameter type.
                    lowerbd, upperbd : real;
                   var result : real);
    ...
    var funval : real;
    begin
    ...
    funval := fun(lowerbd); ----------->lowerbd is actual parameter type checking with formal on top.
    ...
    end;

In the call,   integrate(myfunction(b), a, b. result) ----->  Here, myfunction(b) is actual parameter.

FORTRAN 77 - never check parameter type consistency.

In C & C ++,  pass pointer to functions
                     A function's type is its protocol which includes all parameter type.

Correct Referencing Envirenment
Choices:
1. Shallow Binding - the enviroment of the call, not appropriate for BLOCK_Structure Languages.
2. Deep Binding - the enviroment of the definition of subprogram.
3. ad hoc binding - the enviroment of the call that passed the subprogram as an actual.
Example: (page 358)

procedure SUB1;
   var x : integer;
   procedure SUB2;
    begin
      write('x =', x)
    end;   { of sub2}
   procedure SUB3;
    var x : integer;
    begin
      x := 3;
      SUB4(SUB2);
    end;   { of sub3}
   procedure SUB4(SUBX);
    var x : integer;
    begin
      x := 4;
      SUBX
    end;   { of sub4}
   begin  {of SUB1}
   x := 1;
   SUB3
   end;   { of sub1}
The output depends on SUB2.

1. Shallow bindind:
   Referencing Environment = SUB4
   x bound to local x in SUB4.
   output:    x = 4
2. Deep binding:
   Referencing Environment = SUB1
   x bound to local x in SUB1.
   output:    x = 1
3. ad-hoc binding:
   Referencing Environment = SUB3
   x bound to local x in SUB3.
   output:    x = 3