procedure dynamic is

  type WithdrawProc is 
    access function (x:integer) return integer;

  InsufficientFunds: exception;

  function makeNewBalance (initBalance: integer) 
     return WithDrawProc
  is
     currentBalance: integer;

     function withdraw (amt: integer) return integer is
     begin
       if amt <= currentBalance then
         currentBalance := currentBalance - amt;
       else
         raise InsufficientFunds;
       end if;
       return currentBalance;
     end withdraw;

  begin
     currentBalance := initBalance;
     return withdraw'access;
  end makeNewBalance;

withdraw1, withdraw2: WithdrawProc;

begin
  withdraw1 := makeNewBalance(500);
  withdraw2 := makeNewBalance(100);
end;
