home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l217 / 2.ddi / EXAMPLES / CH07EX03.PRO < prev    next >
Encoding:
Prolog Source  |  1990-03-26  |  339 b   |  18 lines

  1. /*
  2.    Copyright (c) 1986, 90 by Prolog Development Center
  3. */
  4.    
  5. /* Recursive program to compute factorials.
  6.    Ordinary recursion, not tail recursion. */
  7.  
  8. predicates
  9.    factorial(integer, real)
  10.  
  11. clauses
  12.    factorial(1, 1) :- !.
  13.  
  14.    factorial(X, FactX) :-
  15.       Y = X-1,
  16.       factorial(Y, FactY),
  17.       FactX = X*FactY.
  18.