home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l210 / 1.ddi / EXAMPLES.ARC / CH18EX01.PRO < prev    next >
Encoding:
Text File  |  1988-06-21  |  2.8 KB  |  107 lines

  1. /*
  2.    Turbo Prolog 2.0 Chapter 18, Example Program 1
  3.    
  4.    Copyright (c) 1986, 88 by Borland International, Inc
  5.  
  6. */
  7.  
  8. database
  9.    xpositive(symbol, symbol)
  10.    xnegative(symbol, symbol)
  11.       
  12. predicates
  13.    animal_is(symbol)
  14.    it_is(symbol)
  15.    ask(symbol, symbol, symbol)
  16.    remember(symbol, symbol, symbol)
  17.    positive(symbol, symbol)
  18.    negative(symbol, symbol)
  19.    clear_facts
  20.    run
  21.    
  22. clauses
  23.    animal_is(cheetah) :- it_is(mammal),
  24.       it_is(carnivore),
  25.       positive(has, tawny_color),
  26.       positive(has, dark_spots).
  27.  
  28.    animal_is(tiger) :- it_is(mammal),
  29.       it_is(carnivore),
  30.       positive(has, tawny_color),
  31.       positive(has, black_stripes).
  32.  
  33.    animal_is(giraffe) :- it_is(ungulate),
  34.       positive(has, long_neck),
  35.       positive(has, long_legs),
  36.       positive(has, dark_spots).
  37.  
  38.    animal_is(zebra) :- it_is(ungulate), positive(has,black_stripes).
  39.  
  40.    animal_is(ostrich) :- it_is(bird),
  41.       negative(does, fly),
  42.       positive(has, long_neck),
  43.       positive(has, long_legs),
  44.       positive(has, black_and_white_color).
  45.  
  46.    animal_is(penguin) :- it_is(bird),
  47.       negative(does, fly),
  48.       positive(does, swim),
  49.       positive(has, black_and_white_color).
  50.  
  51.    animal_is(albatross) :-
  52.      it_is(bird),  positive(does, fly_well).
  53.       it_is(mammal) :- positive(has, hair).
  54.       it_is(mammal) :- positive(does, give_milk).
  55.       it_is(bird)   :- positive(has, feathers).
  56.       it_is(bird)   :- positive(does, fly), positive(does,lay_eggs).
  57.  
  58.       it_is(carnivore) :- positive(does, eat_meat).
  59.  
  60.       it_is(carnivore) :-
  61.          positive(has, pointed_teeth),
  62.          positive(has, claws),
  63.          positive(has, forward_eyes).
  64.  
  65.       it_is(ungulate) :-
  66.          it_is(mammal), positive(has, hooves).
  67.  
  68.       it_is(ungulate) :- 
  69.         it_is(mammal), positive(does, chew_cud).
  70.  
  71.    positive(X, Y) :-
  72.       xpositive(X, Y), !.
  73.    positive(X, Y) :-
  74.       not(xnegative(X, Y)),
  75.       ask(X, Y, yes).
  76.  
  77.    negative(X, Y) :-
  78.       xnegative(X, Y), !.
  79.    negative(X, Y) :-
  80.       not(xpositive(X, Y)),
  81.       ask(X, Y, no).
  82.  
  83.    ask(X, Y, yes) :-
  84.       !, write(X, " it ", Y, '\n'),
  85.       readln(Reply),
  86.       frontchar(Reply,  'y', _),
  87.       remember(X, Y, yes).
  88.    ask(X, Y, no) :-
  89.       !, write(X, " it ", Y, '\n'),
  90.       readln(Reply),
  91.       frontchar(Reply, 'n', _),
  92.       remember(X, Y, no).
  93.  
  94.    remember(X, Y, yes) :- assertz(xpositive(X,Y)).
  95.    remember(X, Y, no)  :- assertz(xnegative(X,Y)).
  96.  
  97.    clear_facts :- 
  98.       write("\n\nPlease press the space bar to exit\n"),
  99.       retractall(_, dbasedom), readchar(_).
  100.  
  101.    run :-
  102.       animal_is(X), !,
  103.       write("\nYour animal may be a (an) ",X),
  104.       nl, nl, clear_facts.
  105.    run :-
  106.       write("\nUnable to determine what"),
  107.       write("your animal is.\n\n"), clear_facts.