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

  1. /*
  2.    Turbo Prolog 2.0 Chapter 5, Example Program 9
  3.    
  4.    Copyright (c) 1986, 88 by Borland International, Inc
  5.    
  6. */
  7.  
  8. predicates
  9.    repeat
  10.    action(integer,string)
  11.    test(string)
  12.    
  13. goal
  14.    makewindow(1,7,7,"interaction window",0,2,11,43),
  15.    repeat,
  16.    shiftwindow(1),
  17.    clearwindow,
  18.    write("0. Enter 0 to end\n"),
  19.    write("1. Enter 1 to create a window and input\n   a new string\n"),
  20.    write("2. Enter 2 to remove the window and text\n"),
  21.    write("3. Enter 3 to write to existing window\n\n"),
  22.    write("Selection? "),
  23.    readint(Int),nl,
  24.    action(Int,Text),
  25.    Int = 0,!,               /* this cut will prevent backtracking even if you
  26.                                                     have not created a string */
  27.    test(Text).
  28.         
  29. clauses
  30.    action(0,"EXIT"):-!,              /* this cut prevents Turbo Prolog from looking
  31.                                                             at other options. */
  32.       exit.
  33.  
  34.    action(1,Str):- 
  35.       existwindow(2),
  36.       write("You have a window that already exists.\n"),
  37.       write("Do you wish to clear it.(y,n) "),
  38.       readchar(Ans),!,
  39.       Ans='y',    /* If you answer yes to the question this cut prevents the 
  40.                                  backtracking to the second action(1) clause. */
  41.       nl,
  42.       shiftwindow(2),
  43.       clearwindow,
  44.       write("Enter your string\n"),
  45.       readln(Str).
  46.  
  47.    action(1,Str):- !,         /* this cut prevents Turbo Prolog from looking
  48.                                                             at other options. */
  49.       nl,
  50.       makewindow(2,7,7," simple window control ", 12, 3, 12, 40),
  51.       write("Enter your string\n"),
  52.       readln(Str).
  53.  
  54.    action(2,"window removed"):-
  55.       existwindow(2),
  56.       !,    /* If the window has been input, this cut will prevent the second      
  57.                                               action(2) clause from executing */
  58.       shiftwindow(2),
  59.       removewindow,
  60.       clearwindow.
  61.  
  62.    action(2,"ERROR"):- 
  63.       clearwindow,
  64.       write("You must first create a window\n"),
  65.       write("Press any key to continue "),
  66.       readchar(_).
  67.       
  68.    action(3,Str):- 
  69.       existwindow(2),!,
  70.       shiftwindow(2),
  71.       clearwindow,
  72.       write("Enter your string\n"),
  73.       readln(Str).
  74.  
  75.    action(3,Str):- 
  76.       write("There is no window. Do you\n"),
  77.       write("want to create one?(y/n) "),
  78.       readchar(ANS),
  79.       ANS = 'y',nl,
  80.       makewindow(2,7,7," simple window control ",12,3,12,40),
  81.       write("Enter your string\n"),
  82.       readln(Str).
  83.  
  84.    action(_,"ERROR"):-
  85.       write("not a valid option\n"),
  86.       write("press any key to continue").
  87.  
  88.    test(Text):-
  89.       write(Text).
  90.       
  91.    repeat.
  92.    repeat:-repeat.
  93.