inter.tex 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. \chapter{Commands for Interactive Use}\index{Interactive use}
  2. {\REDUCE} is designed as an interactive system, but naturally it can also
  3. operate in a batch processing or background mode by taking its input
  4. command by command from the relevant input stream. There is a basic
  5. difference, however, between interactive and batch use of the system. In
  6. the former case, whenever the system discovers an ambiguity at some point
  7. in a calculation, such as a forgotten type assignment for instance, it asks
  8. the user for the correct interpretation. In batch operation, it is not
  9. practical to terminate the calculation at such points and require
  10. resubmission of the job, so the system makes the most obvious guess of the
  11. user's intentions and continues the calculation.
  12. There is also a difference in the handling of errors. In the former case,
  13. the computation can continue since the user has the opportunity to correct
  14. the mistake. In batch mode, the error may lead to consequent erroneous
  15. (and possibly time consuming) computations. So in the default case, no
  16. further evaluation occurs, although the remainder of the input is checked
  17. for syntax errors. A message {\tt "Continuing with parsing only"}
  18. informs the user that this is happening. On the other hand, the switch
  19. {\tt ERRCONT},\ttindex{ERRCONT} if on, will cause the system to continue
  20. evaluating expressions after such errors occur.
  21. When a syntactical error occurs, the place where the system detected the
  22. error is marked with three dollar signs (\$\$\$). In interactive mode, the
  23. user can then use {\tt ED}\ttindex{ED} to correct the error, or retype the
  24. command. When a non-syntactical error occurs in interactive mode, the
  25. command being evaluated at the time the last error occurred is saved, and
  26. may later be reevaluated by the command {\tt RETRY}.\ttindex{RETRY}
  27. \section{Referencing Previous Results}
  28. It is often useful to be able to reference results of previous
  29. computations during a {\REDUCE} session. For this purpose, {\REDUCE}
  30. maintains a history\index{History} of all interactive inputs and the
  31. results of all interactive computations during a given session. These
  32. results are referenced by the command number that {\REDUCE} prints
  33. automatically in interactive mode. To use an input expression in a new
  34. computation, one writes {\tt input(}$n${\tt )},\ttindex{INPUT} where
  35. $n$ is the command number. To use an output expression, one writes {\tt
  36. WS(}$n${\tt )}.\ttindex{WS} {\tt WS} references the previous command.
  37. E.g., if command number 1 was {\tt INT(X-1,X)}; and the result of command
  38. number 7 was {\tt X-1}, then
  39. \begin{verbatim}
  40. 2*input(1)-ws(7)^2;
  41. \end{verbatim}
  42. would give the result {\tt -1}, whereas
  43. \begin{verbatim}
  44. 2*ws(1)-ws(7)^2;
  45. \end{verbatim}
  46. would yield the same result, but {\em without\/} a recomputation of the
  47. integral.
  48. The operator {\tt DISPLAY}\ttindex{DISPLAY} is available to display previous
  49. inputs. If its argument is a positive integer, {\it n} say, then the
  50. previous n inputs are displayed. If its argument is {\tt ALL} (or in fact
  51. any non-numerical expression), then all previous inputs are displayed.
  52. \section{Interactive Editing}
  53. It is possible when working interactively to edit any {\REDUCE} input that
  54. comes from the user's terminal, and also some user-defined procedure
  55. definitions. At the top level, one can access any previous command string
  56. by the command {\tt ed(}$n${\tt )},\ttindex{ED} where n is the desired
  57. command number as prompted by the system in interactive mode. {\tt ED};
  58. (i.e. no argument) accesses the previous command.
  59. After {\tt ED} has been called, you can now edit the displayed string using a
  60. string editor with the following commands:
  61. \begin{tabular}{lp{\rboxwidth}}
  62. {\tt~~~~~ B} & move pointer to beginning \\
  63. {\tt~~~~~ C<character>} & replace next character by
  64. {\em character} \\
  65. {\tt~~~~~ D} & delete next character \\
  66. {\tt~~~~~ E} & end editing and reread text \\
  67. {\tt~~~~~ F<character>} & move pointer to next
  68. occurrence of {\em character} \\[1.7pt]
  69. {\tt~~~~~ I<string><escape>} &
  70. insert {\em string\/} in front of pointer \\
  71. {\tt~~~~~ K<character>} & delete all characters
  72. until {\em character} \\
  73. {\tt~~~~~ P} & print string from current pointer \\
  74. {\tt~~~~~ Q} & give up with error exit \\
  75. {\tt~~~~~ S<string><escape>} &
  76. search for first occurrence of {\em string},
  77. positioning pointer just before it \\
  78. {\tt~~~~~ space} or {\tt X} & move pointer right
  79. one character.
  80. \end{tabular}
  81. The above table can be displayed online by typing a question mark followed
  82. by a carriage return to the editor. The editor prompts with an angle
  83. bracket. Commands can be combined on a single line, and all command
  84. sequences must be followed by a carriage return to become effective.
  85. Thus, to change the command {\tt x := a+1;} to {\tt x := a+2}; and cause
  86. it to be executed, the following edit command sequence could be used:
  87. \begin{verbatim}
  88. f1c2e<return>.
  89. \end{verbatim}
  90. The interactive editor may also be used to edit a user-defined procedure that
  91. has not been compiled. To do this, one says:
  92. \ttindex{EDITDEF}
  93. \begin{verbatim}
  94. editdef <id>;
  95. \end{verbatim}
  96. where {\tt <id>} is the name of the procedure. The procedure definition
  97. will then be displayed in editing mode, and may then be edited and
  98. redefined on exiting from the editor.
  99. Some versions of {\REDUCE} now include input editing that uses the
  100. capabilities of modern window systems. Please consult your system
  101. dependent documentation to see if this is possible. Such editing
  102. techniques are usually much easier to use then {\tt ED} or {\tt EDITDEF}.
  103. \section{Interactive File Control}
  104. If input is coming from an external file, the system treats it as a batch
  105. processed calculation. If the user desires interactive
  106. \index{Interactive use} response in this case, he can include the command
  107. {\tt on int};\ttindex{INT} in the file. Likewise, he can issue the
  108. command {\tt off int}; in the main program if he does not desire continual
  109. questioning from the system. Regardless of the setting of {\tt INT},
  110. input commands from a file are not kept in the system, and so cannot be
  111. edited using {\tt ED}. However, many implementations of {\REDUCE} provide
  112. a link to an external system editor that can be used for such editing.
  113. The specific instructions for the particular implementation should be
  114. consulted for information on this.
  115. Two commands are available in {\REDUCE} for interactive use of files. {\tt
  116. PAUSE};\ttindex{PAUSE} may be inserted at any point in an input file. When
  117. this command is encountered on input, the system prints the message {\tt
  118. CONT?} on the user's terminal and halts. If the user responds {\tt Y}
  119. (for yes), the calculation continues from that point in the file. If the
  120. user responds {\tt N} (for no), control is returned to the terminal, and
  121. the user can input further statements and commands. Later on he can use
  122. the command {\tt cont;}\ttindex{CONT} to transfer control back to the
  123. point in the file following the last {\tt PAUSE} encountered. A top-level
  124. {\tt pause;}\ttindex{PAUSE} from the user's terminal has no effect.