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

  1. /*
  2.    Turbo Prolog 2.0, Answer to Third Exercise on page 184.
  3.    
  4.    Copyright (c) 1986, 88 by Borland International, Inc
  5.  
  6.    Please note, we have added a KEY associated with each text string
  7.    to make this example a bit more realistic.
  8. */
  9. domains
  10.   text = string
  11.   KEY = string
  12.   
  13. database - textlink
  14.    link(key,text)
  15.   
  16. predicates
  17.   w_str(string)
  18.   options  
  19.   showtext
  20.   showkey(KEY)
  21.   do_choice(char)
  22.   repeat
  23.  
  24. goal
  25.     makewindow(1,11,14," HYPER TEXT ",0,0,25,80,1,-1,"╒╕╘╛═│"),
  26.     repeat,
  27.     clearwindow,
  28.     makewindow(3,10,0,"",23,1,1,78),
  29.     write(" Select your option by selecting first letter"),
  30.     makewindow(2,10,12," Main Menu ",10,30,6,17,1,-1,"┌┐└┘─│"),
  31.     write("Add a new text\n"),
  32.     write("Show all text\n"),
  33.     write("Key text\n"),
  34.     write("Exit program"),
  35.     cursor(0,0),
  36.     readchar(Choice),
  37.     removewindow,
  38.     removewindow,
  39.     do_choice(Choice),
  40.     fail.
  41.     
  42. clauses
  43.   do_choice('a'):-
  44.     not(link(_,_)),!,
  45.     write("Please enter a key for text :"),nl,
  46.     % Your options
  47.     readln(KEY),KEY<>"",nl,nl,
  48.     write("Please enter a line of text :"),nl,
  49.     readln(Text),
  50.     asserta(link(Key,Text)).
  51.  
  52.   do_choice('a'):-
  53.     write("Please enter a key for text :"),
  54.     write("\nOptions are:\n"),
  55.     options,
  56.     readln(KEY),KEY<>"",
  57.     write("\n\nPlease enter a line of text :"),nl,
  58.     readln(Text),
  59.     assertz(link(KEY,Text)).
  60.  
  61.   do_choice('s'):-
  62.     showtext,
  63.     readchar(_).
  64.  
  65.   do_choice('k'):-
  66.     write("enter key:"),nl,
  67.     readln(Key),
  68.     showkey(Key),
  69.     readchar(_).
  70.  
  71.   do_choice('e'):-
  72.     exit.
  73.  
  74.   showtext:-
  75.     link(Key,Text),
  76.     write(KEY,"\n",Text),nl,nl,
  77.     fail.
  78.   showtext.
  79.  
  80.   showkey(KEY):-
  81.     link(Key,Text),!,
  82.     write("\n",Text).
  83.   showkey(Key):-
  84.     write(KEY," is an invalid key."),
  85.     readchar(_).  
  86.  
  87.   Options:-
  88.     link(_,Str),
  89.     w_str(Str),fail.   
  90.   Options.  
  91.  
  92.   w_str(""):-!.
  93.   w_str(Str):-
  94.      fronttoken(Str,Sym,Rest),
  95.      write(Sym),nl,
  96.      w_str(Rest).
  97.    
  98.   repeat.
  99.   repeat:-repeat.
  100.    
  101.