command.tex 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. \section{General Commands}
  2. \begin{Command}{BYE}
  3. The \name{bye} command ends the REDUCE session, returning control to the
  4. program (e.g., the operating system) that called REDUCE. When you are at
  5. the top level, the \name{bye} command exits REDUCE. \name{quit} is a
  6. synonym for \name{bye}.
  7. \end{Command}
  8. \begin{Command}{CONT}
  9. The command \name{cont} returns control to an interactive file after a
  10. \nameref{pause} command that has been answered with \name{n}.
  11. \begin{Examples}
  12. \explanation{Suppose you are in the middle of an interactive file.} \\
  13. & factorize(x**2 + 17*x + 60); \\
  14. & \{\{X + 12,1\},\{X + 5,1\}\} \\
  15. pause; & Cont? (Y or N) \\
  16. n \\
  17. saveas results; \\
  18. factor1 := first results; & FACTOR1 := \{X + 12,1\} \\
  19. factor2 := second results; & FACTOR2 := \{X + 5,1\} \\
  20. cont; & \explanationo{\em the file resumes}
  21. \end{Examples}
  22. \begin{Comments}
  23. A \nameref{pause} allows you to enter your own REDUCE commands, change
  24. switch values, inquire about results, or other such activities. When you
  25. wish to resume operation of the interactive file, use \name{cont}.
  26. \end{Comments}
  27. \end{Command}
  28. \begin{Command}{DISPLAY}
  29. \index{history}\index{interactive}
  30. When given a numeric argument \meta{n}, \name{display} prints the \meta{n}
  31. most recent input statements, identified by prompt numbers. If an empty
  32. pair of parentheses is given, or if \meta{n} is greater than the current
  33. number of statements, all the input statements since the beginning of
  34. the session are printed.
  35. %%%INCONSISTENT??? {\em or}
  36. \begin{Syntax}
  37. \name{display}\(\meta{n}\) {\em or} \name{display}\(\)
  38. \end{Syntax}
  39. \meta{n} should be a positive integer. However, if it is a real number, the
  40. truncated integer value is used, and if a non-numeric argument is used, all
  41. the input statements are printed.
  42. \begin{Comments}
  43. The statements are displayed in upper case, with lines split at semicolons or
  44. dollar signs, as they are in editing. If long files have been input during
  45. the session, the \name{display} command is slow to format these for
  46. printing.
  47. \end{Comments}
  48. \end{Command}
  49. \begin{Command}{LOAD\_PACKAGE}
  50. \index{package}
  51. The \name{load\_package} command is used to load REDUCE packages, such as
  52. \name{gentran} that are not automatically loaded by the system.
  53. \begin{Syntax}
  54. \name{load\_package "}\meta{package\_name}\name{"}
  55. \end{Syntax}
  56. %%% We should probably list the names of the packages here.
  57. A package is only loaded once; subsequent calls of \name{load\_package}
  58. for the same package name are ignored.
  59. \end{Command}
  60. \begin{Command}{PAUSE}
  61. \index{interactive}
  62. The \name{pause} command, given in an interactive file, stops operation and
  63. asks if you want to continue or not.
  64. \begin{Examples}
  65. \explanation{An interactive file is running, and at some point you see the
  66. question} \\
  67. Cont? (Y or N) \\
  68. \explanation{If you type} \\
  69. y\key{Return}\\
  70. \explanation{the file continues to run until the next pause or the end.} \\
  71. \explanation{If you type } \\
  72. n\key{Return} \\
  73. \explanation{you will get a numbered REDUCE prompt, and be allowed to
  74. enter and execute any REDUCE statements. If you later wish to continue with
  75. the file, type} \\
  76. cont; \\
  77. \explanation{and the file resumes.}
  78. \end{Examples}
  79. To use \name{pause} in your own interactive files, type
  80. \name{pause;}
  81. in the file wherever you want it.
  82. \begin{Comments}
  83. \name{pause} does not allow you to continue without typing either \name{y}
  84. or \name{n}. Its use is to slow down scrolling of interactive files, or to
  85. let you change parameters or switch settings for the calculations.
  86. If you have stopped an interactive file at a \name{pause,} and do not wish to
  87. resume the file, type \name{end;}. This does not end the REDUCE session, but
  88. stops input from the file. A second \name{end;} ends the REDUCE session.
  89. However, if you have pauses from more than one file stacked up, an \name{end;}
  90. brings you back to the top level, not the file directly above.
  91. A \name{pause} typed from the terminal has no effect.
  92. \end{Comments}
  93. \end{Command}
  94. \begin{Command}{QUIT}
  95. The \name{quit} command ends the REDUCE session, returning control to the
  96. program (e.g., the operating system) that called REDUCE. When you are at
  97. the top level, the \name{quit} command exits REDUCE. \nameref{bye} is a
  98. synonym for \name{quit}.
  99. \end{Command}
  100. \begin{Operator}{RECLAIM}
  101. \index{memory}
  102. \begin{Comments}
  103. REDUCE's memory is in a storage structure called a heap. As REDUCE
  104. statements execute, chunks of memory are used up. When these chunks are no
  105. longer needed, they remain idle. When the memory is almost full,
  106. the system executes a garbage collection, reclaiming space that is no
  107. longer needed, and putting all the free space at one end. Depending on
  108. the size of the image REDUCE is using,
  109. garbage collection needs to be done more or less often. A
  110. larger image means fewer but longer garbage collections.
  111. Regardless of memory size,
  112. if you ask REDUCE to do something ridiculous, like \name{factorial(2000)}, it may
  113. garbage collect many times.
  114. \end{Comments}
  115. \end{Operator}
  116. \begin{Command}{REDERR}
  117. \index{error handling}
  118. The \name{rederr} command allows you to print an error message from inside
  119. a \nameref{procedure} or a \nameref{block} statement.
  120. The calculation is gracefully terminated.
  121. \begin{Syntax}
  122. \name{rederr} \meta{message}
  123. \end{Syntax}
  124. \meta{message} is an error message, usually inside double quotation marks
  125. (a \nameref{string}).
  126. \begin{Examples}
  127. \begin{multilineinput}
  128. procedure fac(n);
  129. if not (fixp(n) and n>=0)
  130. then rederr "Choose nonneg. integer only"
  131. else for i := 0:n-1 product i+1;
  132. \end{multilineinput} &
  133. fac \\
  134. fac a; &
  135. ***** Choose nonneg. integer only \\
  136. fac 5; & 120
  137. \end{Examples}
  138. \begin{Comments}
  139. The above procedure finds the factorial of its argument.
  140. If n is not a positive integer or 0, an error message is returned.
  141. If your procedure is executed in a file, the usual error message is
  142. printed, followed by \name{Cont? (Y or N)}, just as any other error does from
  143. a file. Although the procedure is gracefully terminated, any switch settings or
  144. variable assignments you made before the error occurred are not undone. If you
  145. need to clean up such items before exiting, use a group statement, with the
  146. \name{rederr} command as its last statement.
  147. \end{Comments}
  148. \end{Command}
  149. \begin{Command}{RETRY}
  150. \index{interactive}
  151. The \name{retry} command allows you to retry the latest statement that resulted
  152. in an error message.
  153. \begin{Examples}
  154. matrix a; \\
  155. det a; & ***** Matrix A not set \\
  156. a := mat((1,2),(3,4)); & \begin{multilineoutput}{6cm}
  157. A(1,1) := 1
  158. A(1,2) := 2
  159. A(2,1) := 3
  160. A(2,2) := 4
  161. \end{multilineoutput}\\
  162. retry; & -2
  163. \end{Examples}
  164. \begin{Comments}
  165. \name{retry} remembers only the most recent statement that resulted in an
  166. error message. It allows you to stop and fix something obvious, then
  167. continue on your way without retyping the original command.
  168. \end{Comments}
  169. \end{Command}
  170. \begin{Command}{SAVEAS}
  171. The \name{saveas} command saves the current workspace under the name of its
  172. argument.
  173. \begin{Syntax}
  174. \name{saveas} \meta{identifier}
  175. \end{Syntax}
  176. \meta{identifier} can be any valid REDUCE identifier.
  177. \begin{Examples}
  178. \explanation{(The numbered prompts are shown below, unlike in most examples)}\\
  179. 1: solve(x^2-3);&
  180. \{x=sqrt(3),x= - sqrt(3)\}\\
  181. 2: saveas rts(0)\$\\
  182. 3: rts(0);&
  183. \{x=sqrt(3),x= - sqrt(3)\}\\
  184. \end{Examples}
  185. \begin{Comments}
  186. \name{saveas} works only for the current workspace, the last algebraic
  187. expression produced by REDUCE. This allows you to save a result that you
  188. did not assign to an identifier when you originally typed the input.
  189. For access to previous output use \nameref{ws}.
  190. \end{Comments}
  191. \end{Command}
  192. \begin{Command}{SHOWTIME}
  193. \index{time}
  194. The \name{showtime} command prints the elapsed system time since the last
  195. call of this command or since the beginning of the session, if it has not
  196. been called before.
  197. \begin{Examples}
  198. showtime; & Time: 1020 ms \\
  199. factorize(x^4 - 8x^4 + 8x^2 - 136x - 153);
  200. & \{X - 9,X^{2} + 17,X + 1\} \\
  201. showtime; & Time: 920 ms
  202. \end{Examples}
  203. \begin{Comments}
  204. The time printed is either the elapsed cpu time or the elapsed wall clock
  205. time, depending on your system. \name{showtime} allows you to see the
  206. system time resources REDUCE uses in its calculations. Your time readings
  207. will of course vary from this example according to the system you use.
  208. \end{Comments}
  209. \end{Command}
  210. \begin{Command}{WRITE}
  211. \index{output}
  212. The \name{write} command explicitly writes its arguments to the output device
  213. (terminal or file).
  214. \begin{Syntax}
  215. \name{write} \meta{item}\{,\meta{item}\}\optional
  216. \end{Syntax}
  217. \meta{item} can be an expression, an assignment or a \nameref{string}
  218. enclosed in double quotation marks (\name{"}).
  219. \begin{Examples}
  220. write a, sin x, "this is a string"; & ASIN(X)this is a string \\
  221. write a," ",sin x," this is a string"; & A SIN(X) this is a string \\
  222. if not numberp(a) then write "the symbol ",a;
  223. & the symbol A \\
  224. array m(10); \\
  225. for i := 1:5 do write m(i) := 2*i; &
  226. \begin{multilineoutput}{6cm}
  227. M(1) := 2
  228. M(2) := 4
  229. M(3) := 6
  230. M(4) := 8
  231. M(5) := 10
  232. \end{multilineoutput}\\
  233. m(4); & 8
  234. \end{Examples}
  235. \begin{Comments}
  236. The items specified by a single \name{write} statement print on a single line
  237. unless they are too long. A printed line is always ended with a carriage
  238. return, so the next item printed starts a new line.
  239. When an assignment statement is printed, the assignment is also made. This
  240. allows you to get feedback on filling slots in an array with a \nameref{for}
  241. statement, as shown in the last example above.
  242. \end{Comments}
  243. \end{Command}