home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lifeos2.zip / LIFE-1.02 / TESTS / LF / DICT.LF < prev    next >
Text File  |  1996-06-04  |  746b  |  27 lines

  1. % Dictionary program in Life.
  2. % Author: Peter Van Roy
  3.  
  4. % Insert, look up, or check a definition in an ordered binary tree
  5.  
  6. delay_check(tree)?
  7. :: tree(name=>string,def=>string,left=>tree,right=>tree).
  8.  
  9. contains(tree(name=>N,def=>D),   Name, Def) :-
  10.         Name=N, Def=D.
  11.  
  12. contains(tree(name=>N,left=>L),  Name, Def) :-
  13.         N$>Name,
  14.         contains(L, Name, Def).
  15.  
  16. contains(tree(name=>N,right=>R), Name, Def) :-
  17.         N$=<Name,
  18.         contains(R, Name, Def).
  19.  
  20. main :-
  21.         CN="cat", CD="furry feline",
  22.         DN="dog", DD="furry canine",
  23.         contains(T,CN,CD),  % Insert cat definition
  24.         contains(T,DN,DD),  % Insert dog definition
  25.         contains(T,CN,Def), % Look up cat definition
  26.         write("A ",CN," is a ",Def),nl.
  27.