--
-- This is a test of function
--
package test31 is body
    function factorial (b : integer): integer is 
	function add (b, c : in integer): integer is
	begin
		return b+c;
	end;
	function times (b, c : in integer): integer is
	    a, i : integer;
	begin
	    i := 1;
            a := 0;
	    loop
		a := add(a, c);
		exit when i == b;
		i := i+1;
	    end loop;
	    return a;
	end;
    begin
	if b <> 0 then 
	    return b*factorial(b-1);
	else
	    return 1;
	end if;
    end;
    type complex is record r, i: float; end record;
    function makecomplex(r, i: float): complex is
	result: complex;
    begin
	result.r := r; result.i := i;
	return result;
    end;
begin 
    write ("factorial(4) = ", factorial(4), " (should be 24)");
end.
