home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / borland / jnfb88.arc / TAIL.ARC / FACT2.PRO < prev    next >
Text File  |  1987-10-22  |  520b  |  28 lines

  1. /* FACT2.PRO */
  2.  
  3. /* Tail recursive program
  4.    to compute factorials */
  5.  
  6. PREDICATES
  7.  
  8.    factorial(integer,real)
  9.    factorial_aux(integer,real,integer,real)
  10.  
  11.    /* Numbers likely to exceed
  12.       32767 are declared as reals */
  13.  
  14. CLAUSES
  15.  
  16.    factorial(N,FactN) :-
  17.         factorial_aux(N,FactN,1,1).
  18.  
  19.    factorial_aux(N,FactN,I,P) :-
  20.         I <= N,
  21.         NewP = P*I,
  22.         NewI = I+1,
  23.         !,
  24.         factorial_aux(N,FactN,NewI,NewP).
  25.  
  26.    factorial_aux(N,FactN,I,FactN) :-
  27.         I > N.
  28.