io.tex 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. \chapter{File Handling Commands}\index{File handling}
  2. In many applications, it is desirable to load previously prepared {\REDUCE}
  3. files into the system, or to write output on other files. {\REDUCE} offers
  4. four commands for this purpose, namely, {\tt IN}, {\tt OUT}, {\tt SHUT},
  5. {\tt LOAD}, and {\tt LOAD\_PACKAGE}. The first\ttindex{IN}\ttindex{OUT}
  6. \ttindex{SHUT} three operators are described here; {\tt LOAD} and {\tt
  7. LOAD\_PACKAGE} are discussed in Section~\ref{sec-load}.
  8. \section{IN Command}\ttindex{IN}
  9. This command takes a list of file names as argument and directs the system
  10. to input\index{Input} each file (that should contain {\REDUCE} statements
  11. and commands) into the system. File names can either be an identifier or
  12. a string. The explicit format of these will be system dependent and, in
  13. many cases, site dependent. The explicit instructions for the
  14. implementation being used should therefore be consulted for further
  15. details. For example:
  16. \begin{verbatim}
  17. in f1,"ggg.rr.s";
  18. \end{verbatim}
  19. will first load file {\tt F1}, then {\tt ggg.rr.s}. When a semicolon is
  20. used as the terminator of the IN statement, the statements in the file are
  21. echoed on the terminal or written on the current output file. If \$
  22. \index{Command terminator} is used as the terminator, the input is not
  23. shown. Echoing of all or part of the input file can be prevented, even if
  24. a semicolon was used, by placing an {\tt off echo;}\ttindex{ECHO} command
  25. in the input file.
  26. Files to be read using {\tt IN} should end with {\tt ;END;}. Note the two
  27. semicolons! First of all, this is protection against obscure difficulties
  28. the user will have if there are, by mistake, more {\tt BEGIN}s than
  29. {\tt END}s on the file. Secondly, it triggers some file control book-keeping
  30. which may improve system efficiency. If {\tt END} is omitted, an error
  31. message {\tt "End-of-file read"} will occur.
  32. \section{OUT Command}\ttindex{OUT}
  33. This command takes a single file name as argument, and directs output to
  34. that file from then on, until another {\tt OUT} changes the output file,
  35. or {\tt SHUT} closes it. Output can go to only one file at a time,
  36. although many can be open. If the file has previously been used for
  37. output during the current job, and not {\tt SHUT},\ttindex{SHUT} the new
  38. output is appended to the end of the file. Any existing file is erased
  39. before its first use for output in a job, or if it had been {\tt SHUT}
  40. before the new {\tt OUT}.
  41. To output on the terminal without closing the output file, the reserved
  42. file name T (for terminal) may be used. For example,
  43. {\tt out ofile;} will direct output to the file {\tt OFILE} and
  44. {\tt out t;} will direct output to the user's terminal.
  45. The output sent to the file will be in the same form that it would have on
  46. the terminal. In particular {\tt x\verb|^|2} would appear on two lines, an
  47. {\tt X} on the lower line and a 2 on the line above. If the purpose of the
  48. output file is to save results to be read in later, this is not an
  49. appropriate form. We first must turn off the {\tt NAT} switch that
  50. specifies that output should be in standard mathematical notation.
  51. {\it Example:} To create a file {\tt ABCD} from which it will be possible
  52. to read -- using {\tt IN} -- the value of the expression {\tt XYZ}:
  53. \begin{verbatim}
  54. off echo$ % needed if your input is from a file.
  55. off nat$ % output in IN-readable form. Each expression
  56. % printed will end with a $ .
  57. out abcd$ % output to new file
  58. linelength 72$ % for systems with fixed input line length.
  59. xyz:=xyz; % will output "XYZ := " followed by the value
  60. % of XYZ
  61. write ";end"$ % standard for ending files for IN
  62. shut abcd$ % save ABCD, return to terminal output
  63. on nat$ % restore usual output form
  64. \end{verbatim}
  65. \section{SHUT Command}\ttindex{SHUT}
  66. This command takes a list of names of files that have been previously
  67. opened via an {\tt OUT} statement and closes them. Most systems require this
  68. action by the user before he ends the {\REDUCE} job (if not sooner),
  69. otherwise the output may be lost. If a file is shut and a further {\tt OUT}
  70. command issued for the same file, the file is erased before the new output
  71. is written.
  72. If it is the current output file that is shut, output will switch to the
  73. terminal. Attempts to shut files that have not been opened by {\tt OUT},
  74. or an input file, will lead to errors.