home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l217 / 2.ddi / EXAMPLES / CH05EX09.PRO < prev    next >
Encoding:
Prolog Source  |  1990-03-26  |  2.7 KB  |  90 lines

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