util.tex 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. \chapter{{\REDUCE} and Rlisp Utilities}
  2. {\REDUCE} and its associated support language system Rlisp\index{Rlisp}
  3. include a number of utilities which have proved useful for program
  4. development over the years. The following are supported in most of the
  5. implementations of {\REDUCE} currently available.
  6. \section{The Standard Lisp Compiler}\index{Compiler}
  7. Many versions of {\REDUCE} include a Standard Lisp compiler that is
  8. automatically loaded on demand. You should check your system specific
  9. user guide to make sure you have such a compiler. To make the compiler
  10. active, the switch {\tt COMP}\ttindex{COMP} should be turned on. Any
  11. further definitions input after this will be compiled automatically. If
  12. the compiler used is a derivative version of the original Griss-Hearn
  13. compiler,
  14. (M. L. Griss and A.
  15. C. Hearn, ``A Portable LISP Compiler", SOFTWARE --- Practice and Experience
  16. 11 (1981) 541-605),
  17. there are other switches that might also be
  18. used in this regard. However, these additional switches are not supported
  19. in all compilers. They are as follows:
  20. %\ttindex{PLAP}\ttindex{PGWD}\ttindex{PWRDS}
  21. {\renewcommand{\arraystretch}{2}
  22. \begin{tabular}{lp{\reduceboxwidth}}
  23. {\tt PLAP} & If ON, causes the printing of the
  24. portable macros produced by the compiler; \\
  25. %
  26. {\tt PGWD} & If ON, causes the printing of the
  27. actual assembly language instructions generated from the macros; \\
  28. %
  29. {\tt PWRDS} & If ON, causes a statistic
  30. message of the form \newline
  31. {\tt <function> COMPILED, <words> WORDS, <words> LEFT} \newline
  32. to be printed. The first number is the number of words of binary
  33. program space the compiled function took, and the second number
  34. the number of words left unused in binary program space. \\
  35. \end{tabular}}
  36. \section{Fast Loading Code Generation Program}\index{Fast loading of code}
  37. \label{sec-load}
  38. In most versions of {\REDUCE}, it is possible to take any set of Lisp, Rlisp
  39. or {\REDUCE} commands and build a fast loading version of them. In Rlisp or
  40. {\REDUCE}, one does the following:
  41. \begin{verbatim}
  42. faslout <filename>;
  43. <commands or IN statements>
  44. faslend;
  45. \end{verbatim}
  46. To load such a file, one uses the command {\tt LOAD},\ttindex{LOAD}
  47. e.g. {\tt load foo;}
  48. or {\tt load foo,bah;}
  49. This process produces a fast-loading version of the original file. In some
  50. implementations, this means another file is created with the same name but
  51. a different extension. For example, in PSL-based systems, the extension is
  52. {\tt b} (for binary). In CSL-based systems, however, this process adds the
  53. fast-loading code to a single file in which all such code is stored.
  54. Particular functions are provided by CSL for managing this file, and
  55. described in the CSL user documentation.
  56. In doing this build, as with the production of a Standard Lisp form of
  57. such statements, it is important to remember that some of the commands
  58. must be instantiated during the building process. For example, macros
  59. must be expanded, and some property list operations must happen.
  60. The {\REDUCE} sources should be consulted for further details on this.
  61. % To facilitate this, the {\tt EVAL} and {\tt IGNORE} flags may be
  62. % used. Note also that there can be no {\tt LOAD} command within the input
  63. % statements.
  64. To avoid excessive printout, input statements should be followed by a \$
  65. instead of the semicolon. With {\tt LOAD} however, the input doesn't
  66. print out regardless of which terminator is used with the command.
  67. If you subsequently change the source files used in producing a fast
  68. loading file, don't forget to repeat the above process in order to update
  69. the fast loading file correspondingly. Remember also that the text which
  70. is read in during the creation of the fast load file, in the compiling
  71. process described above, is {\em not\/} stored in your {\REDUCE}
  72. environment, but only translated and output. If you want to use the file
  73. just created, you must then use {\tt LOAD} to load the output of the
  74. fast-loading file generation program.
  75. When the file to be loaded contains a complete package for a given
  76. application, {\tt LOAD\_PACKAGE}\ttindex{LOAD\_PACKAGE} rather than
  77. {\tt LOAD} should be used. The syntax is the same. However,
  78. {\tt LOAD\_PACKAGE} does some additional bookkeeping such as recording that
  79. this package has now been loaded, that is required for the correct
  80. operation of the system.
  81. \section{The Standard Lisp Cross Reference Program}\index{Cross reference}
  82. {\tt CREF}\ttindex{CREF} is a Standard Lisp program for processing a
  83. set of Standard LISP function definitions to produce:
  84. \begin{enumerate}
  85. \item A ``summary'' showing:
  86. \begin{enumerate}
  87. \item A list of files processed;
  88. \item A list of ``entry points'' (functions which are not called or
  89. are only called by themselves);
  90. \item A list of undefined functions (functions called but not
  91. defined in this set of functions);
  92. \item A list of variables that were used non-locally but not
  93. declared {\tt GLOBAL} or {\tt FLUID} before their use;
  94. \item A list of variables that were declared {\tt GLOBAL} but not used
  95. as {\tt FLUID}s, i.e., bound in a function;
  96. \item A list of {\tt FLUID} variables that were not bound in a function
  97. so that one might consider declaring them {\tt GLOBAL}s;
  98. \item A list of all {\tt GLOBAL} variables present;
  99. \item A list of all {\tt FLUID} variables present;
  100. \item A list of all functions present.
  101. \end{enumerate}
  102. \item A ``global variable usage'' table, showing for each non-local
  103. variable:
  104. \begin{enumerate}
  105. \item Functions in which it is used as a declared {\tt FLUID} or {\tt GLOBAL};
  106. \item Functions in which it is used but not declared;
  107. \item Functions in which it is bound;
  108. \item Functions in which it is changed by {\tt SETQ}.
  109. \end{enumerate}
  110. \item A ``function usage'' table showing for each function:
  111. \begin{enumerate}
  112. \item Where it is defined;
  113. \item Functions which call this function;
  114. \item Functions called by it;
  115. \item Non-local variables used.
  116. \end{enumerate}
  117. \end{enumerate}
  118. The program will also check that functions are called with the correct
  119. number of arguments, and print a diagnostic message otherwise.
  120. The output is alphabetized on the first seven characters of each function
  121. name.
  122. \subsection{Restrictions}
  123. Algebraic procedures in {\REDUCE} are treated as if they were symbolic, so
  124. that algebraic constructs will actually appear as calls to symbolic
  125. functions, such as {\tt AEVAL}.
  126. \subsection{Usage}
  127. To invoke the cross reference program, the switch {\tt CREF}
  128. \ttindex{CREF} is used. {\tt on cref} causes the cref program to load
  129. and the cross-referencing process to begin. After all the required
  130. definitions are loaded, {\tt off cref} will cause the cross-reference
  131. listing to be produced. For example, if you wish to cross-reference all
  132. functions in the file {\tt tst.red}, and produce the cross-reference
  133. listing in the file {\tt tst.crf}, the following sequence can be used:
  134. \begin{verbatim}
  135. out "tst.crf";
  136. on cref;
  137. in "tst.red"$
  138. off cref;
  139. shut "tst.crf";
  140. \end{verbatim}
  141. To process more than one file, more {\tt IN} statements may be added
  142. before the call of {\tt off cref}, or the {\tt IN} statement changed to
  143. include a list of files.
  144. \subsection{Options}
  145. Functions with the flag {\tt NOLIST} will not be examined or output.
  146. Initially, all Standard Lisp functions are so flagged. (In fact, they are
  147. kept on a list {\tt NOLIST!*}, so if you wish to see references to {\em
  148. all} functions, then {\tt CREF} should be first loaded with the command {\tt
  149. load cref}, and this variable then set to {\tt NIL}).
  150. It should also be remembered that any macros with the property list flag
  151. {\tt EXPAND}, or, if the switch {\tt FORCE} is on, without the property
  152. list flag {\tt NOEXPAND}, will be expanded before the definition is seen
  153. by the cross-reference program, so this flag can also be used to select
  154. those macros you require expanded and those you do not.
  155. \section{Prettyprinting Reduce Expressions}\index{Prettyprinting}
  156. {\REDUCE} includes a module for printing {\REDUCE} syntax in a standard
  157. format. This module is activated by the switch {\tt PRET},
  158. \ttindex{PRET} which is normally off.
  159. Since the system converts algebraic input into an equivalent symbolic form,
  160. the printing program tries to interpret this as an algebraic expression
  161. before printing it. In most cases, this can be done successfully. However,
  162. there will be occasional instances where results are printed in symbolic
  163. mode form that bears little resemblance to the original input, even though
  164. it is formally equivalent.
  165. If you want to prettyprint a whole file, say {\tt off output,msg;}
  166. \ttindex{MSG} and (hopefully) only clean output will result. Unlike {\tt
  167. DEFN},\ttindex{DEFN} input is also evaluated with {\tt PRET}
  168. \ttindex{PRET} on.
  169. \section{Prettyprinting Standard Lisp S-Expressions}\index{Prettyprinting}
  170. REDUCE includes a module for printing
  171. S-expressions in a standard format. The Standard Lisp function for this
  172. purpose is {\tt PRETTYPRINT}\ttindex{PRETTYPRINT} which takes a Lisp
  173. expression and prints the formatted equivalent.
  174. Users can also have their {\REDUCE} input printed in this form by use of
  175. the switch {\tt DEFN}.\ttindex{DEFN} This is in fact a convenient way to
  176. convert {\REDUCE} (or Rlisp) syntax into Lisp. {\tt off msg;} will prevent
  177. warning messages from being printed.
  178. NOTE: When {\tt DEFN} is on, input is not evaluated.