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

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