Programming-Idioms

History of Idiom 31 > diff from v7 to v8

Edit summary for version 8 :

Version 7

2015-08-20, 10:33:38

Version 8

2015-08-22, 21:30:37

Idiom #31 Recursive factorial (simple)

Create recursive function f which returns the factorial of non-negative integer i, calculated from f(i-1)

Idiom #31 Recursive factorial (simple)

Create recursive function f which returns the factorial of non-negative integer i, calculated from f(i-1)

Code
type
  TPositiveInt = 0..MaxInt;

function _f(_i: TPositiveInt): Integer;
begin
  if (_i < 2) then
    Result := 1
  else
    Result := _f(_i - 1);
end; 
Comments bubble
The definition of type TPositiveInt allows for rangechecking on the input.
MaxInt is already defined in the language.