fork download
  1. predicates
  2. action(integer,string)
  3. test(string)
  4.  
  5. goal
  6. makewindow(1,7,7,"interaction window",0,2,11,43),
  7. shiftwindow(1),
  8. clearwindow,
  9. write("0. Enter 0 to end\n"),
  10. write("1. Enter 1 to create a window and input\n a new string\n"),
  11. write("2. Enter 2 to remove the window and text\n"),
  12. write("3. Enter 3 to write to existing window\n\n"),
  13. write("Selection? "),
  14. readint(Int),nl,
  15. action(Int,Text),
  16. Int = 0,!, /* this cut will prevent backtracking even if you have not created a string */
  17. test(Text).
  18.  
  19. clauses
  20. action(0,"EXIT"):-!, /* this cut prevents Turbo Prolog from looking at other options. */
  21. exit.
  22.  
  23. action(1,Str):-
  24. existwindow(2),
  25. write("You have a window that already exists.\n"),
  26. write("Do you wish to clear it.(y,n) "),
  27. readchar(Ans),!,
  28. Ans='y', /* If you answer yes to the question this cut prevents the backtracking to the second action(1) clause. */
  29. nl,
  30. shiftwindow(2),
  31. clearwindow,
  32. write("Enter your string\n"),
  33. readln(Str).
  34.  
  35. action(1,Str):- !, /* this cut prevents Turbo Prolog from looking at other options. */
  36. nl,
  37. makewindow(2,7,7," simple window control ", 12, 3, 12, 40),
  38. write("Enter your string\n"),
  39. readln(Str).
  40.  
  41. action(2,"window removed"):-
  42. existwindow(2),
  43. !, /* If the window has been input, this cut will prevent the second action(2) clause from executing */
  44. shiftwindow(2),
  45. removewindow,
  46. clearwindow.
  47.  
  48. action(2,"ERROR"):-
  49. clearwindow,
  50. write("You must first create a window\n"),
  51. write("Press any key to continue "),
  52. readchar(_).
  53.  
  54. action(3,Str):-
  55. existwindow(2),!,
  56. shiftwindow(2),
  57. clearwindow,
  58. write("Enter your string\n"),
  59. readln(Str).
  60.  
  61. action(3,Str):-
  62. write("There is no window. Do you\n"),
  63. write("want to create one?(y/n) "),
  64. readchar(ANS),
  65. ANS = 'y',nl,
  66. makewindow(2,7,7," simple window control ",12,3,12,40),
  67. write("Enter your string\n"),
  68. readln(Str).
  69.  
  70. action(_,"ERROR"):-
  71. write("not a valid option\n"),
  72. write("press any key to continue").
  73.  
  74. test(Text):-
  75. write(Text).
  76.  
Success #stdin #stdout #stderr 0.03s 6968KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/e87DQz/prog:2:2: Syntax error: Operator expected
ERROR: /home/e87DQz/prog:22:2: Syntax error: Operator expected
ERROR: /home/e87DQz/prog:79:
	No permission to modify static procedure `repeat/0'
ERROR: /home/e87DQz/prog:80:
	No permission to modify static procedure `repeat/0'
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit