home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l210 / 1.ddi / EXAMPLES.ARC / CH09EX01.PRO < prev    next >
Encoding:
Prolog Source  |  1988-06-21  |  1.2 KB  |  53 lines

  1. /*
  2.    Turbo Prolog 2.0 Chapter 9, Example Program 1
  3.    
  4.    Copyright (c) 1986, 88 by Borland International, Inc
  5.    
  6. */
  7.    
  8. domains
  9.    thing = string
  10.    conds = cond*
  11.    cond  = string
  12.  
  13. database
  14.    is_a(thing, thing, conds)
  15.    type_of(thing, thing, conds)
  16.    false(cond)
  17.  
  18. predicates
  19.    run(thing)
  20.    ask(conds)
  21.  
  22. clauses
  23.    run(Item):-
  24.       is_a(X, Item, List),
  25.       ask(List),
  26.       type_of(ANS, X, List2),
  27.       ask(List2),
  28.       write("The ", Item," you need is a/an ", Ans),nl.
  29.  
  30.    run(_):- 
  31.       write("This program does not have enough "),
  32.       write("data to draw any conclusions."),
  33.       nl.
  34.  
  35.    ask([]).
  36.    ask([H|T]):-
  37.       not(false(H)),
  38.       write("Does this thing help you to "),
  39.       write(H," (enter y/n)"),
  40.       readchar(Ans), nl, Ans='y',
  41.       ask(T).
  42.  
  43.    ask([H|_]):-
  44.       assertz(false(H)), fail.
  45.  
  46.    is_a(language, tool, ["communicate"]).
  47.    is_a(hammer, tool, ["build a house", "fix a fender", "crack a nut"]).
  48.    is_a(sewing_machine, tool, ["make clothing", "repair sails"]).
  49.    is_a(plow, tool, ["prepare fields", "farm"]).
  50.  
  51.    type_of(english, language, ["communicate with people"]).
  52.    type_of(prolog, language, ["communicate with a computer"]).
  53.