home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Borland Plateform / Turbo Prolog 2 / EXAMPL63.PRO < prev    next >
Encoding:
Text File  |  1986-04-25  |  1.7 KB  |  60 lines

  1. code = 1000 trail = 1000
  2. domains
  3.     term = reference var(vid); symb(symbol) ; 
  4.            cmp(fid, terml)
  5.     terml = reference term*
  6.     atom = atom(aid, terml)
  7.     atoml = atom*
  8.     e = e(vid, term)
  9.     env = reference e*
  10.     fid, aid, vid = symbol
  11.     
  12. database
  13.     clause(atom, atoml)
  14.     
  15. predicates
  16.     call(atom)
  17.     unify_term(term, term, env)
  18.     unify_terml(terml, terml, env)
  19.     unify_littl(atoml, env)
  20.     member(e, env)
  21.  
  22. /*goal call(atom(likes,[Name,Activity])),
  23.         write(Name,Activity).*/
  24.  
  25. clauses
  26.         call(atom(Id, Terml)) :-
  27.          clause(atom(Id,Terml1), Body),
  28.         free(E), 
  29.         unify_terml(Terml, Terml1, E), 
  30.         unify_littl(Body, E).
  31.     unify_terml([], [], _).
  32.     unify_terml([Trm1|Tl1],[Trm2|Tl2],E) :-
  33.         unify_term(Trm1, Trm2, E),
  34.         unify_terml(Tl1, Tl2, E).
  35.         
  36.     unify_term(Term, var(X), Env) :- 
  37.         member(e(X,Term),Env), !.
  38.     unify_term(symb(X), symb(X), _).
  39.     unify_term(cmp(Id, L1), cmp(Id,L2),E) :-
  40.         unify_terml(L1, L2, E).
  41.         
  42.     unify_littl([],_).
  43.     unify_littl([atom(Id,Terml)|Atoml],Env) :-
  44.         unify_terml(Call,Terml,Env),call(atom(Id,Call)),
  45.         unify_littl(Atoml,Env).
  46.         
  47.     member(X,[X|_]).
  48.     member(X,[_|L]) :-
  49.         member(X,L).
  50.  
  51. /* *********************************************************** */
  52. /*     DATABASE FACTS ASSERTED  *                             */  
  53. /* *********************************************************** */
  54.          clause(atom(likes,[symb(tom),symb(baseball)]), []).        
  55.          clause(atom(likes,[symb(windy),symb(tennis)]), []).
  56.       clause(atom(likes,[symb(john),symb(football)]), []).
  57.       clause(atom(likes,[symb(eric),symb(swimming)]), []).
  58.          clause(atom(likes,[symb(bill),var(x)]),    
  59.                [atom(likes,[symb(tom), var(x)])]).
  60.