home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / aijournl / 1986_09 / turbo2.ltg < prev   
Text File  |  1986-10-30  |  836b  |  45 lines

  1.  
  2.  
  3. Turbo PROLOG:
  4. Database Access Benchmark
  5.  
  6.  
  7.  
  8. /* Test database storage and retrieval by asserting lots of facts and looking
  9.    them up. */
  10.  
  11.  
  12. DATABASE
  13.  
  14. fact(INTEGER)
  15.  
  16.  
  17. PREDICATES
  18.  
  19. test(INTEGER)
  20. test2(INTEGER, INTEGER)
  21.  
  22.  
  23. CLAUSES
  24.  
  25. /* Tail recursively look up a numbered fact in the database and the assert
  26.    its successor.  First argument is current fact number, second argument
  27.    is limiting fact number to stop at. */
  28.  
  29. test2(X,X).
  30. test2(X,Y) :- fact(X), Z = X + 1, assert(fact(Z)), test2(Z,Y).
  31.  
  32. /* Shorthand predicate to default the test to start with fact(1). */
  33.  
  34. test(Y) :- test2(1,Y).
  35.  
  36. fact(1).                /* Seed the database with the first fact */
  37.  
  38.  
  39. GOAL
  40.  
  41. /* Prompt for the limiting fact number and run the benchmark. */
  42.  
  43. nl, write(ready), nl, readint(X), test(X), write(done), nl.
  44.  
  45.