Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /pages/trunk/doc/interact.html
ViewVC logotype

Annotation of /pages/trunk/doc/interact.html

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2484 - (view) (download) (as text)

1 : macqueen 953 <!-- Changed by: John Reppy, 19-Dec-1997 -->
2 :     <!-- Changed by: Andrew Appel, 31-Oct-1997 -->
3 :     <HTML>
4 :     <HEAD>
5 :     <TITLE>SML/NJ Interactive System</TITLE></HEAD>
6 :     <BODY BGCOLOR="ffffff">
7 :     <H1>Standard ML of New Jersey Interactive System</H1>
8 :     <blockquote>
9 :     This section explains some of the basic elements of using the Standard
10 :     ML of New Jersey compiler as an interactive system into which you
11 :     enter declarations and expressions or load code from source files.
12 :     This is the most accessible mode of using the compiler, but for any
13 :     programs of nontrivial size we recommend that the <a href="CM/index.html">
14 :     Compilation Manager</a> be used to organize the compilation process.
15 :     <p>
16 :     We assume below that you are using the compiler under Unix. The
17 :     behavior will be somewhat different under MS Windows or the Macintosh
18 :     OS.
19 :    
20 :     <h2>Running Standard ML</h2>
21 :    
22 :     Type ``<code>sml</code>'' from the shell. This puts you into the
23 :     interactive system. The top level prompt is ``-'', and the
24 :     secondary prompt (printed when input is incomplete) is ``=''.
25 :     If you get the secondary prompt when you don't expect it,
26 :     typing ``<code>;</code> <i>return</i>'' will often complete your input, or
27 :     typing your interrupt character (e.g., control-C)
28 :     will cancel your input and return to the ML top level.
29 :     <p>
30 :     If ``<code>sml</code>'' doesn't work, ask where <code>sml</code> has
31 :     been installed on your machine and use the appropriate path name or
32 :     redefine your PATH environment variable.
33 :    
34 :     <h2>Interactive input</h2>
35 :    
36 :     Input to the top level interpreter (i.e., declarations and
37 :     expressions) must be terminated by a semicolon (and carriage
38 :     return) before the system will evaluate it. The system then prints
39 :     out a response indicating the effect of the evaluation.
40 :     Expressions are treated as implicit declarations of a standard
41 :     variable <code>it</code>. For example,
42 :    
43 :     <table>
44 :     <tr><td><code>- 3;</code><td><i>user input after prompt</i>
45 :     <tr><td><code>val it = 3 : int<td><i>system response</i>
46 :     </table>
47 :    
48 :     This means that the value of the last top level expression evaluated
49 :     can be referred to using the variable ``<code>it</code>.''
50 :    
51 :     <h2>Interrupting compilation or execution</h2>
52 :    
53 :     Typing the interrupt character (typically control-C)
54 :     should interrupt the compiler and return you
55 :     to top level.
56 :    
57 :     <h2>Exiting the interactive system.</h2>
58 :    
59 :     Typing control-D (EOF) at top level will cause an exit to the shell
60 :     (or the parent process from which <code>sml</code> was run). One can also terminate
61 :     by calling <code>OS.Process.exit(OS.Process.success)</code>.
62 :    
63 :     <h2>Loading ML source text from a file</h2>
64 :    
65 :     The function <code>use: string -> unit</code> interprets its argument as a
66 :     file name relative to <code>sml</code>'s current directory and loads the text
67 :     from that file as though it had been typed in. This should normally
68 :     be executed at top level, but the loaded files can also contain calls
69 :     of <code>use</code> to recursively load other files. It is a bad idea to call
70 :     <code>use</code> within an expression or declaration, because the effects are
71 :     not well-defined.
72 :     <p>
73 :     For industrial-strength multi-module software systems, the
74 :     the <a href="CM">Compilation Manager</a>
75 :     is more appropriate than <code>use</code>.
76 :    
77 :     <!--
78 :     <h2>Saving an image of the system</h2>
79 :    
80 :     Use the function <code>exportML: string -> bool</code> to save an image of the
81 :     current <code>sml</code> system (including the environment that you have
82 :     built) in a file.
83 :     -->
84 :    
85 :     <h2>Error messages</h2>
86 :    
87 :     The compiler attempts to recover from syntactic errors so that it can
88 :     also produce semantic (type-checking) errors during the same
89 :     compilation. Syntactic error recovery is more accurate for source
90 :     files loaded by <code>use</code> or CM than it is from declarations typed
91 :     directly into the interactive system -- this is because lookahead is
92 :     not possible when text is entered one line at a time.
93 :     <p>
94 :     When compiling files, the error messages include line numbers and
95 :     character positions within the line. For example:
96 :     <pre>
97 :     - if true
98 :     = then 5 true
99 :     = else 6;
100 :     std_in:7.6-7.11 Error: operator is not a function
101 :     operator: int
102 :     in expression:
103 :     5 true
104 :     -
105 :     </pre>
106 :     Here the location information <code>std_in:7.6-7.11</code> indicates that the
107 :     erroneous expression ``<code>5 true</code>'' occupies characters 6 through 11
108 :     of the 7th line of input from <code>std_in</code>. For simple syntactic
109 :     errors this position information is usually accurate or perhaps off by
110 :     just one line. For some classes of errors the line numbers may not be very
111 :     useful, because they delineate a potentially large declaration
112 :     containing the error. If the error occurs in a file being loaded by
113 :     <code>use</code>, the line numbers will refer to lines in the file being
114 :     loaded.
115 :     <p>
116 :     There are a number of different forms of type error message, and it
117 :     may require some practice before you become adept at interpreting
118 :     them. The most common form indicates a mismatch between the type of a
119 :     function (or operator) and its argument (or operand).
120 :     A representation of the offending expression is usually included, but
121 :     this is an image of the internal abstract syntax for the expression
122 :     and may differ significantly from the original source code. For
123 :     instance, an expression ``<code>if </code>e1<code> then </code>e2<code> else </code>e3''
124 :     is represented internally as a <code>case</code> expression over a boolean value:
125 :     ``$<code>case </code> e1 <code> of true => </code> e2 <code> | false => </code> e3.''
126 :     <p>
127 :     All the error messages produced by SML/NJ are documented in the
128 :     <a href="errors.html"><strong>SML/NJ Error and Warning Messages</strong></a> page.
129 :    
130 :     <h2>Compiler interface</h2>
131 :    
132 :     Most users will interact with the compiler by loading code via the
133 :     <code>use</code> command or under control of the
134 :     <a href="CM/index.html"><i>Compilation Manager</i></a>.
135 :     However, some control of individual compiler phases is possible
136 :     through the
137 :     <a href="Compiler/pages/control.html"><code>Compiler.Control</code></a>
138 :     structure.
139 :    
140 :     <h2>Printing</h2>
141 :    
142 :     The structure
143 :     <a href="Compiler/pages/printcontrol.html"><code>Compiler.Control.Print</code></a>
144 :     contains several useful flags and functions with which you can control
145 :     or redirect compiler error, diagnostic, and result messages.
146 :     Among other things, there is a variable <code>printDepth</code> that
147 :     controls the depth of printing of large structured values.
148 :    
149 :     <h2>Interacting with the operating system</h2>
150 :    
151 :     The structures <code>IO</code>, <code>OS</code>, and others contain functions
152 :     for such tasks as executing other programs from within <code>sml</code>
153 :     and changing the current directory. These are documented in
154 :     <a href="basis/index.html">
155 :     The Standard ML Basis Library</a> manual.
156 :    
157 :     <h2>Emacs support</h2>
158 :     The directory contrib/emacs contains
159 :     <a href="mailto:mjm@dcs.ed.ac.uk"> Matthew J. Morley's</a>
160 :     <a href="Emacs/sml-mode.html">sml-mode</a> package that supports editing SML
161 :     source code and interacting with <code>sml</code> under GNU emacs.
162 : dbm 2484 The latest version of the sml-mode package is available at
163 :     <a href="http://www.iro.umontreal.ca/~monnier/elisp/">
164 :     http://www.iro.umontreal.ca/~monnier/elisp/</a>.
165 :    
166 : macqueen 953 <!--
167 :     and from
168 :     <a href="http://www.scs.leeds.ac.uk/mjm/sml-mode/">http://www.scs.leeds.ac.uk/mjm/sml-mode/</a>.
169 :     -->
170 :    
171 :     </blockquote>
172 :     <HR>
173 :     <CENTER><STRONG>
174 :     | <A HREF="../index.html">SML/NJ Home Page</A> | <br>
175 :     | <A HREF="index.html">SML/NJ Documentation Home Page</A> |
176 :     </STRONG></CENTER>
177 :     <HR>
178 : mblume 1292 Send your comments to <img src="../smlnj-list-logo.jpg" align=center>.<br>
179 : macqueen 953 <FONT SIZE="-3">
180 :     Copyright &#169; 1998,
181 :     <A HREF="http://www.lucent.com/">Lucent Technologies; Bell Laboratories</A>.
182 :     <BR>
183 :     </FONT>
184 :     </BODY>
185 :     </HTML>

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0