The Ada Program: side.adb

  1 -- side.adb:  two unrelated blocks illustrating side effects
  2 
  3 -- The parameter profile or parameter specification is the description
  4 -- of an interface between the subprogram author and the caller.  Any
  5 -- effects of the subprogram other than through the parameters are called
  6 -- side effects.  Side effects should be avoided.
  7 
  8 with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
  9 
 10 procedure Side is
 11 
 12 begin
 13 
 14    declare
 15       X, Y: Integer;
 16       procedure Bad (A: out Integer) is
 17       begin
 18          X := 3;   -- change to non-local variable
 19       end;
 20    begin
 21       Bad (Y);
 22    end;
 23 
 24 
 25    declare
 26       X, Y: Integer;
 27       function Bad (A: Integer) return Integer is
 28       begin
 29          X := 3;   -- change to non-local variable
 30          Put (A);  -- output statement
 31          return (A+3);
 32       end;
 33    begin
 34       Y := Bad (4);
 35    end;
 36 
 37 end Side;