home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l210 / 1.ddi / ANSWERS.ARC / ANS_155.PRO < prev    next >
Encoding:
Text File  |  1988-06-21  |  861 b   |  29 lines

  1. /*
  2.    Turbo Prolog 2.0, Answer to Exercise on page 155.
  3.    
  4.    Copyright (c) 1986, 88 by Borland International, Inc
  5. */
  6.    
  7. % Uses backtracking to print all solutions to a query.
  8.  
  9. Predicates
  10.    country(symbol,real)
  11.    %      (name  ,population)  
  12.    print_countries
  13.  
  14. Clauses
  15.    country(england,3e7).
  16.    country(france,2.3e7).
  17.    country(germany,1.6e7).
  18.    country(denmark,2.4e6).
  19.    country(canada,7.3e6).
  20.    country(chile,2.5e).
  21.  
  22.    print_countries :- 
  23.        country(X,P),     /* bind country name to X and population to P */
  24.        P > 1e7,          /* is population greater than 10 million? */
  25.         write(X),         /* write the value of X */
  26.         nl,               /* start a new line */
  27.         fail.             /* force backtracking to find all solutions */
  28.    print_countries.       /* make sure print_countries succeeds */
  29.