home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l217 / 2.ddi / EXAMPLES / CH09EX01.PRO < prev    next >
Encoding:
Prolog Source  |  1990-03-26  |  1.1 KB  |  50 lines

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