manual-Z-H-4.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!--
  4. Generated from manual.tex by tex2page, v 2005-03-30
  5. (running on MzScheme 299.101, unix),
  6. (c) Dorai Sitaram,
  7. http://www.ccs.neu.edu/~dorai/tex2page/tex2page-doc.html
  8. -->
  9. <head>
  10. <title>
  11. The Incomplete Scheme 48 Reference Manual for release 1.3
  12. </title>
  13. <link rel="stylesheet" type="text/css" href="manual-Z-S.css" title=default>
  14. <meta name=robots content="noindex,follow">
  15. </head>
  16. <body>
  17. <div id=content>
  18. <div align=right class=navigation><i>[Go to <span><a href="manual.html">first</a>, <a href="manual-Z-H-3.html">previous</a></span><span>, <a href="manual-Z-H-5.html">next</a></span> page<span>; &nbsp;&nbsp;</span><span><a href="manual-Z-H-2.html#node_toc_start">contents</a></span><span><span>; &nbsp;&nbsp;</span><a href="manual-Z-H-13.html#node_index_start">index</a></span>]</i></div>
  19. <p></p>
  20. <a name="node_chap_2"></a>
  21. <h1 class=chapter>
  22. <div class=chapterheading><a href="manual-Z-H-2.html#node_toc_node_chap_2">Chapter 2</a></div><br>
  23. <a href="manual-Z-H-2.html#node_toc_node_chap_2">User's guide</a></h1>
  24. <p>This chapter details Scheme&nbsp;48's user interface: its command-line arguments,
  25. command processor, debugger, and so forth.</p>
  26. <p>
  27. </p>
  28. <a name="node_sec_2.1"></a>
  29. <h2><a href="manual-Z-H-2.html#node_toc_node_sec_2.1">2.1&nbsp;&nbsp;Command line arguments</a></h2>
  30. <p>A few command line arguments are processed by Scheme&nbsp;48 as
  31. it starts up.</p>
  32. <p>
  33. <tt>scheme48</tt>
  34. [<tt>-i</tt> <i>image</i>]
  35. [<tt>-h</tt> <i>heapsize</i>]
  36. [<tt>-a</tt> <i>argument <tt>...</tt></i>]</p>
  37. <p>
  38. </p>
  39. <dl><dt></dt><dd>
  40. </dd><dt><b><tt>-i</tt> <i>image</i></b></dt><dd>
  41. specifies a heap image file to resume. This defaults to a heap
  42. image that runs a Scheme command processor. Heap images are
  43. created by the <tt>,dump</tt> and <tt>,build commands</tt>, for which see below.<p>
  44. </p>
  45. </dd><dt><b><tt>-h</tt> <i>heapsize</i></b></dt><dd>
  46. specifies how much space should be reserved for allocation.
  47. <i>Heapsize</i> is in words (where one word = 4 bytes), and covers both
  48. semispaces, only one of which is in use at any given time (except
  49. during garbage collection). Cons cells are currently 3 words, so
  50. if you want to make sure you can allocate a million cons cells,
  51. you should specify <tt>-h 6000000</tt> (actually somewhat more than this,
  52. to account for the initial heap image and breathing room).
  53. The default heap size is 3000000 words. The system will use a
  54. larger heap if the specified (or default) size is less than
  55. the size of the image being resumed.<p>
  56. </p>
  57. <p>
  58. </p>
  59. </dd><dt><b><tt>-a</tt> <i>argument <tt>...</tt></i></b></dt><dd>
  60. is only useful with images built using <tt>,build</tt>.
  61. The arguments are passed as a list of strings to the procedure specified
  62. in the <tt>,build</tt> command as for example:
  63. <pre class=verbatim>&gt; (define (f a) (for-each display a) (newline) 0)
  64. &gt; ,build f foo.image
  65. &gt; ,exit
  66. % scheme48vm -i foo.image -a mumble &quot;foo x&quot;
  67. mumblefoo x
  68. %
  69. </pre><p>
  70. </p>
  71. </dd></dl><p></p>
  72. <p>
  73. The usual definition of the <tt>s48</tt> or <tt>scheme48</tt> command is actually a
  74. shell script that starts up the Scheme&nbsp;48 virtual machine with a
  75. <tt>-i <i>imagefile</i></tt>
  76. specifying the development environment heap image and a
  77. <tt>-o <i>vm-executable</i></tt> specifying the location of the virtual-machine
  78. executable (the executable is needed for loading external code on some
  79. versions of Unix; see section&nbsp;<a href="manual-Z-H-9.html#node_sec_7.4">7.4</a> for more information).
  80. The file <tt>go</tt> in the Scheme&nbsp;48 installation source directory is an example
  81. of such a shell script.</p>
  82. <p>
  83. </p>
  84. <a name="node_sec_2.2"></a>
  85. <h2><a href="manual-Z-H-2.html#node_toc_node_sec_2.2">2.2&nbsp;&nbsp;Command processor</a></h2>
  86. <p>When you invoke the default heap image, a command processor starts
  87. running.
  88. The command processor acts as both a read-eval-print loop, reading
  89. expressions, evaluating them, and printing the results, and as
  90. an interactive debugger and data inspector.
  91. See Chapter&nbsp;<a href="manual-Z-H-5.html#node_chap_3">3</a> for
  92. a description of the command processor.</p>
  93. <p>
  94. </p>
  95. <a name="node_sec_2.3"></a>
  96. <h2><a href="manual-Z-H-2.html#node_toc_node_sec_2.3">2.3&nbsp;&nbsp;Editing</a></h2>
  97. <p>We recommend running Scheme&nbsp;48 under GNU Emacs or XEmacs using the
  98. <tt>cmuscheme48</tt> command package.
  99. This is in the Scheme&nbsp;48 distribution's <tt>emacs/</tt> subdirectory and
  100. is included in XEmacs's <tt>scheme</tt> package.
  101. It is a variant of the <tt>cmuscheme</tt> library, which
  102. comes to us courtesy of Olin Shivers, formerly of CMU.
  103. You might want to put the following in your Emacs init file (<tt>.emacs</tt>):
  104. </p>
  105. <pre class=verbatim>(setq scheme-program-name &quot;scheme48&quot;)
  106. (autoload 'run-scheme
  107. &quot;cmuscheme48&quot;
  108. &quot;Run an inferior Scheme process.&quot;
  109. t)
  110. </pre><p>
  111. The Emacs function <tt>run-scheme</tt> can then be used to start a process
  112. running the program <tt>scheme48</tt> in a new buffer.
  113. To make the <tt>autoload</tt> and <tt>(require <tt>...</tt>)</tt> forms work, you will
  114. also need
  115. to put the directory containing <tt>cmuscheme</tt> and related files in your
  116. emacs load-path:
  117. </p>
  118. <pre class=verbatim>(setq load-path
  119. (append load-path '(&quot;<i>scheme-48-directory</i>/emacs&quot;)))
  120. </pre><p>
  121. Further documentation can be found in the files <tt>emacs/cmuscheme48.el</tt> and
  122. <tt>emacs/comint.el</tt>.</p>
  123. <p>
  124. </p>
  125. <a name="node_sec_2.4"></a>
  126. <h2><a href="manual-Z-H-2.html#node_toc_node_sec_2.4">2.4&nbsp;&nbsp;Performance</a></h2>
  127. <p></p>
  128. <p>
  129. If you want to generally have your code run faster than it normally
  130. would, enter <tt>inline-values</tt> mode before loading anything. Otherwise
  131. calls to primitives (like <tt>+</tt> and <tt>cons</tt>) and in-line procedures
  132. (like <tt>not</tt> and <tt>cadr</tt>) won't be open-coded, and programs will run
  133. more slowly.</p>
  134. <p>
  135. The system doesn't start in <tt>inline-values</tt> mode by default because the
  136. Scheme report permits redefinitions of built-in procedures. With
  137. this mode set, such redefinitions don't work according to the report,
  138. because previously compiled calls may have in-lined the old
  139. definition, leaving no opportunity to call the new definition.</p>
  140. <p>
  141. <tt>Inline-values</tt> mode is controlled by the <tt>inline-values</tt> switch.
  142. <tt>,set inline-values</tt> and <tt>,unset inline-values</tt> turn it on and off.</p>
  143. <p>
  144. </p>
  145. <a name="node_sec_2.5"></a>
  146. <h2><a href="manual-Z-H-2.html#node_toc_node_sec_2.5">2.5&nbsp;&nbsp;Disassembler</a></h2>
  147. <p>The <tt>,dis</tt> command prints out the disassembled byte codes of a procedure.
  148. </p>
  149. <pre class=verbatim>&gt; ,dis cons
  150. cons
  151. 0 (protocol 2)
  152. 2 (pop)
  153. 3 (make-stored-object 2 pair)
  154. 6 (return)
  155. &gt;
  156. </pre><p>
  157. The current byte codes are listed in the file <tt>scheme/vm/arch.scm</tt>.
  158. A somewhat out-of-date description of them can be found in
  159. [<a href="manual-Z-H-12.html#node_bib_5">5</a>].</p>
  160. <p>
  161. The command argument is optional; if unsupplied it defaults to the
  162. current focus object (<tt>##</tt>).</p>
  163. <p>
  164. The disassembler can also be invoked on continuations and templates.</p>
  165. <p>
  166. </p>
  167. <a name="node_sec_2.6"></a>
  168. <h2><a href="manual-Z-H-2.html#node_toc_node_sec_2.6">2.6&nbsp;&nbsp;Module system</a></h2>
  169. <p></p>
  170. <p>
  171. This section gives a brief description of modules and related entities.
  172. For detailed information, including a description of the module
  173. configuration language, see
  174. chapter <a href="manual-Z-H-6.html#node_chap_4">4</a>.</p>
  175. <p>
  176. </p>
  177. <p>
  178. A <em>module</em> is an isolated namespace, with visibility of bindings
  179. controlled by module descriptions written in a special
  180. configuration language.
  181. A module may be instantiated as a <em>package</em>, which is an environment
  182. in which code can be evaluated.
  183. Most modules are instantiated only once and so have a unique package.
  184. A <em>structure</em> is a subset of the bindings in a package.
  185. Only by being included in a structure can a binding be
  186. made visible in other packages.
  187. A structure has two parts, the package whose bindings are being exported
  188. and the set of names that are to be exported.
  189. This set of names is called an <em>interface</em>.
  190. A module then has three parts:
  191. </p>
  192. <ul>
  193. <li><p>a set of structures whose bindings are to be visible within the module
  194. </p>
  195. <li><p>the source code to be evaluated within the module
  196. </p>
  197. <li><p>a set of exported interfaces
  198. </p>
  199. </ul><p>
  200. Instantiating a module produces a package and a set of structures, one for
  201. each of the exported interfaces.</p>
  202. <p>
  203. The following example uses <tt>define-structure</tt> to create a module that
  204. implements simple cells as pairs, instantiates this module, and binds the
  205. resulting structure to <tt>cells</tt>.
  206. The syntax <tt>(export <i>name <tt>...</tt></i>)</tt> creates an interface
  207. containing <i>name <tt>...</tt></i>.
  208. The <tt>open</tt> clause lists structures whose bindings are visible
  209. within the module.
  210. The <tt>begin</tt> clause contains source code.
  211. </p>
  212. <pre class=verbatim>(define-structure cells (export make-cell
  213. cell-ref
  214. cell-set!)
  215. (open scheme)
  216. (begin (define (make-cell x)
  217. (cons 'cell x))
  218. (define cell-ref cdr)
  219. (define cell-set! set-cdr!)))
  220. </pre><p></p>
  221. <p>
  222. Cells could also have been implemented using the
  223. record facility described in section&nbsp;<a href="manual-Z-H-7.html#node_sec_5.10">5.10</a>
  224. and available in structure <tt>define-record-type</tt>.
  225. </p>
  226. <pre class=verbatim>(define-structure cells (export make-cell
  227. cell-ref
  228. cell-set!)
  229. (open scheme define-record-types)
  230. (begin (define-record-type cell :cell
  231. (make-cell value)
  232. cell?
  233. (value cell-ref cell-set!))))
  234. </pre><p></p>
  235. <p>
  236. With either definition the resulting structure can be used in other
  237. modules by including <tt>cells</tt> in an <tt>open</tt> clause.</p>
  238. <p>
  239. The command interpreter is always operating within a particular package.
  240. Initially this is a package in which only the standard Scheme bindings
  241. are visible.
  242. The bindings of other structures can be made visible by using the
  243. <tt>,open</tt> command described in section&nbsp;<a href="manual-Z-H-5.html#node_sec_3.4">3.4</a> below.</p>
  244. <p>
  245. Note that this initial package does not include the configuration language.
  246. Module code needs to be evaluated in the configuration package, which can
  247. be done by using the <tt>,</tt>config command:
  248. </p>
  249. <pre class=verbatim>&gt; ,config (define-structure cells <tt>...</tt>)
  250. &gt; ,open cells
  251. &gt; (make-cell 4)
  252. '(cell . 4)
  253. &gt; (define c (make-cell 4))
  254. &gt; (cell-ref c)
  255. 4
  256. </pre><p></p>
  257. <p>
  258. </p>
  259. <a name="node_sec_2.7"></a>
  260. <h2><a href="manual-Z-H-2.html#node_toc_node_sec_2.7">2.7&nbsp;&nbsp;Library</a></h2>
  261. <p>A number of useful utilities are either built in to Scheme&nbsp;48 or can
  262. be loaded from an external library. These utilities are not visible
  263. in the user environment by default, but can be made available with the
  264. <tt>open</tt> command. For example, to use the <tt>tables</tt> structure, do
  265. </p>
  266. <pre class=verbatim>&gt; ,open tables
  267. &gt;
  268. </pre><p></p>
  269. <p>
  270. If the utility is not already loaded, then the <tt>,open</tt> command will
  271. load it.
  272. Or, you can load something explicitly (without opening it) using the
  273. <tt>load-package</tt> command:
  274. </p>
  275. <pre class=verbatim>&gt; ,load-package queues
  276. &gt; ,open queues
  277. </pre><p></p>
  278. <p>
  279. When loading a utility, the message &quot;Note: optional optimizer not
  280. invoked&quot; is innocuous. Feel free to ignore it.</p>
  281. <p>
  282. See also the package system documentation, in
  283. chapter&nbsp;<a href="manual-Z-H-6.html#node_chap_4">4</a>.</p>
  284. <p>
  285. Not all of the the libraries available in Scheme&nbsp;48 are described in this
  286. manual.
  287. All are listed in files <tt>rts-packages.scm</tt>,
  288. <tt>comp-packages.scm</tt>, <tt>env-packages.scm</tt>, and
  289. <tt>more-packages.scm</tt> in the <tt>scheme</tt> directory of the distribution,
  290. and the bindings they
  291. export are listed in <tt>interfaces.scm</tt> and
  292. <tt>more-interfaces.scm</tt> in the same directory.</p>
  293. <p>
  294. </p>
  295. <p>
  296. </p>
  297. <div align=right class=navigation><i>[Go to <span><a href="manual.html">first</a>, <a href="manual-Z-H-3.html">previous</a></span><span>, <a href="manual-Z-H-5.html">next</a></span> page<span>; &nbsp;&nbsp;</span><span><a href="manual-Z-H-2.html#node_toc_start">contents</a></span><span><span>; &nbsp;&nbsp;</span><a href="manual-Z-H-13.html#node_index_start">index</a></span>]</i></div>
  298. </div>
  299. </body>
  300. </html>