home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l210 / 1.ddi / ANSWERS.ARC / ANS_121A.PRO next >
Encoding:
Prolog Source  |  1988-06-21  |  1.8 KB  |  70 lines

  1. /*
  2.    Turbo Prolog 2.0, Answer to first Exercise on page 121.
  3.    
  4.    Copyright (c) 1986, 88 by Borland International, Inc
  5. */
  6.  
  7. Domains
  8.     person = symbol
  9.  
  10. Predicates
  11.     special_taxpayer(person)
  12.     average_taxpayer(person)
  13.     is_a_citizen(person)
  14.     married(person,person)
  15.     has_kids(person,integer)
  16.     has_two_kids(person,integer)
  17.     makes_bucks(person,integer)
  18.     right_income(person,integer)
  19.  
  20. Clauses
  21.     is_a_citizen(tom).
  22.     is_a_citizen(albert).
  23.     is_a_citizen(suzie).
  24.     is_a_citizen(bonnie).
  25.     is_a_citizen(Person):- 
  26.         married(Person,Spouse),
  27.         is_a_citizen(Spouse),!.   /* The cut must be placed here to prevent
  28.                                      unnecessary backtracking. To see this, 
  29.                                      trace thru the program, first with
  30.                                      and then without the cut.                  
  31.                                   */
  32.     married(tom,chris).
  33.     married(albert,rachel).
  34.     married(fred,suzie).
  35.     married(duke,joanne).
  36.  
  37.     has_kids(albert,3).
  38.     has_kids(suzie,2).
  39.     has_kids(fred,2).
  40.     has_kids(bonnie,1).
  41.     has_kids(tom,0).
  42.  
  43.     has_two_kids(Person,X):-
  44.         has_kids(Person,X),
  45.         X=2.                   
  46.  
  47.     makes_bucks(tom,250).
  48.     makes_bucks(fred,3000).
  49.     makes_bucks(albert,1500).
  50.     makes_bucks(suzie,0).
  51.  
  52.     right_income(Person,N):-
  53.         makes_bucks(Person,N),
  54.         500 <= N,               
  55.         N <= 2000.
  56.  
  57.     average_taxpayer(Person):-
  58.         is_a_citizen(Person),
  59.         right_income(Person,_),
  60.         has_two_kids(Person,_),
  61.         married(Person,_),
  62.         write(Person," is an average taxpayer").
  63.  
  64.     special_taxpayer(Person):-
  65.         not(average_taxpayer(Person)),
  66.         write(Person," is a special taxpayer").
  67.  
  68. Goal
  69.     special_taxpayer(fred).
  70.