home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / borland / jnfb88.arc / TAIL.ARC / BADCOUNT.PRO next >
Text File  |  1987-10-22  |  1KB  |  48 lines

  1. /* BADCOUNT.PRO */
  2.  
  3. /* Three procedures that are like
  4.    COUNT.PRO but not tail recursive;
  5.    they run out of memory after
  6.    a few hundred iterations. */
  7.  
  8. PREDICATES
  9.  
  10.   badcount1(real)
  11.   badcount2(real)
  12.   badcount3(real)
  13.   check(real)
  14.  
  15. CLAUSES
  16.  
  17. /* badcount1:
  18.    The recursive call is not the last step. */
  19.  
  20.   badcount1(X) :- write(X),nl,
  21.                   NewX = X+1,
  22.                   badcount1(NewX),
  23.                   nl.
  24.  
  25. /* badcount2:
  26.    There is a clause that has not been tried
  27.    at the time the recursive call is made. */
  28.  
  29.   badcount2(X) :- write(X),nl,
  30.                   NewX = X+1,
  31.                   badcount2(NewX).
  32.  
  33.   badcount2(X) :- X < 0,
  34.                   write("X is negative.").
  35.  
  36.  
  37. /* badcount3:
  38.    There is an untried alternative in a
  39.    procedure called before the recursive call. */
  40.  
  41.   badcount3(X) :- write(X),nl,
  42.                   NewX = X+1,
  43.                   check(NewX),
  44.                   badcount3(NewX).
  45.  
  46.   check(Z) :- Z >= 0.
  47.   check(Z) :- Z < 0.
  48.