documentation improvements from Frederik Eaton
[ghc-hetmet.git] / docs / users_guide / ghci.xml
index 528a652..35aa7cd 100644 (file)
@@ -611,7 +611,7 @@ Prelude IO>
       </sect3>
 
       <sect3>
-        <title>The <literal>:main</literal> command</title>
+        <title>The <literal>:main</literal> and <literal>:run</literal> commands</title>
 
         <para>
           When a program is compiled and executed, it can use the
@@ -636,6 +636,37 @@ Prelude> :main foo bar
 ["foo","bar"]
 </screen>
 
+        <para>
+            We can also quote arguments which contains characters like
+            spaces, and they are treated like Haskell strings, or we can
+            just use Haskell list syntax:
+        </para>
+
+<screen>
+Prelude> :main foo "bar baz"
+["foo","bar baz"]
+Prelude> :main ["foo", "bar baz"]
+["foo","bar baz"]
+</screen>
+
+        <para>
+            Finally, other functions can be called, either with the
+            <literal>-main-is</literal> flag or the <literal>:run</literal>
+            command:
+        </para>
+
+<screen>
+Prelude> let foo = putStrLn "foo" >> System.Environment.getArgs >>= print
+Prelude> let bar = putStrLn "bar" >> System.Environment.getArgs >>= print
+Prelude> :set -main-is foo
+Prelude> :main foo "bar baz"
+foo
+["foo","bar baz"]
+Prelude> :run bar ["foo", "bar baz"]
+bar
+["foo","bar baz"]
+</screen>
+
       </sect3>
     </sect2>
   
@@ -814,10 +845,12 @@ def = toEnum 0
     <para>GHCi contains a simple imperative-style debugger in which you can
       stop a running computation in order to examine the values of
       variables.  The debugger is integrated into GHCi, and is turned on by
-      default: no flags are required to enable the debugging facilities.  There
-      is one major restriction: breakpoints and single-stepping are only
-      available in <emphasis>interpreted</emphasis> modules; compiled code is
-      invisible to the debugger.</para>
+      default: no flags are required to enable the debugging
+      facilities.  There is one major restriction: breakpoints and
+      single-stepping are only available in interpreted modules;
+      compiled code is invisible to the debugger<footnote><para>Note that packages
+      only contain compiled code, so debugging a package requires
+      finding its source and loading that directly.</para></footnote>.</para>
 
     <para>The debugger provides the following:
     <itemizedlist>
@@ -852,9 +885,12 @@ def = toEnum 0
     </para>
       
     <para>There is currently no support for obtaining a &ldquo;stack
-      trace&rdquo;, but the tracing and history features provide a useful
-      second-best, which will often be enough to establish the context of an
-      error.</para>
+    trace&rdquo;, but the tracing and history features provide a
+    useful second-best, which will often be enough to establish the
+    context of an error.  For instance, it is possible to break
+    automatically when an exception is thrown, even if it is thrown
+    from within compiled code (see <xref
+    linkend="ghci-debugger-exceptions" />).</para>
       
     <sect2 id="breakpoints">
       <title>Breakpoints and inspecting variables</title>
@@ -2119,6 +2155,37 @@ Prelude> :main foo bar
 ["foo","bar"]
 </screen>
 
+        <para>
+            We can also quote arguments which contains characters like
+            spaces, and they are treated like Haskell strings, or we can
+            just use Haskell list syntax:
+        </para>
+
+<screen>
+Prelude> :main foo "bar baz"
+["foo","bar baz"]
+Prelude> :main ["foo", "bar baz"]
+["foo","bar baz"]
+</screen>
+
+        <para>
+            Finally, other functions can be called, either with the
+            <literal>-main-is</literal> flag or the <literal>:run</literal>
+            command:
+        </para>
+
+<screen>
+Prelude> let foo = putStrLn "foo" >> System.Environment.getArgs >>= print
+Prelude> let bar = putStrLn "bar" >> System.Environment.getArgs >>= print
+Prelude> :set -main-is foo
+Prelude> :main foo "bar baz"
+foo
+["foo","bar baz"]
+Prelude> :run bar ["foo", "bar baz"]
+bar
+["foo","bar baz"]
+</screen>
+
         </listitem>
       </varlistentry>
 
@@ -2560,18 +2627,34 @@ Prelude> :set -fno-glasgow-exts
     </indexterm>
 
     <para>When it starts, unless the <literal>-ignore-dot-ghci</literal>
-    flag is given, GHCi reads and executes commands from
-    <filename>./.ghci</filename>, followed by
-    <filename>$HOME/.ghci</filename>.</para>
-
-    <para>The <filename>.ghci</filename> in your home directory is
-    most useful for turning on favourite options (eg. <literal>:set
-    +s</literal>), and defining useful macros.  Placing a
-    <filename>.ghci</filename> file in a directory with a Haskell
-    project is a useful way to set certain project-wide options so you
-    don't have to type them everytime you start GHCi: eg. if your
-    project uses GHC extensions and CPP, and has source files in three
-    subdirectories A, B and C, you might put the following lines in
+    flag is given, GHCi reads and executes commands from the following
+    files, in this order, if they exist:</para>
+
+    <orderedlist>
+    <listitem>
+      <para><filename>./.ghci</filename></para>
+    </listitem>
+    <listitem>
+      <para><literal><replaceable>appdata</replaceable>/ghc/ghci.conf</literal>,
+      where <replaceable>appdata</replaceable> depends on your system,
+      but is usually something like <literal>C:/Documents and Settings/<replaceable>user</replaceable>/Application Data</literal></para>
+    </listitem>
+    <listitem>
+      <para>On Unix: <literal>$HOME/.ghc/ghci.conf</literal></para>
+    </listitem>
+    <listitem>
+      <para><literal>$HOME/.ghci</literal></para>
+    </listitem>
+   </orderedlist>
+
+    <para>The <filename>ghci.conf</filename> file is most useful for
+    turning on favourite options (eg. <literal>:set +s</literal>), and
+    defining useful macros.  Placing a <filename>.ghci</filename> file
+    in a directory with a Haskell project is a useful way to set
+    certain project-wide options so you don't have to type them
+    everytime you start GHCi: eg. if your project uses GHC extensions
+    and CPP, and has source files in three subdirectories A, B and C,
+    you might put the following lines in
     <filename>.ghci</filename>:</para>
 
 <screen>
@@ -2585,7 +2668,7 @@ Prelude> :set -fno-glasgow-exts
     until the next <literal>:load</literal>, though.)</para>
 
     <para>Two command-line options control whether the
-    <filename>.ghci</filename> files are read:</para>
+    startup files files are read:</para>
 
     <variablelist>
       <varlistentry>
@@ -2594,8 +2677,8 @@ Prelude> :set -fno-glasgow-exts
           <indexterm><primary><option>-ignore-dot-ghci</option></primary></indexterm>
         </term>
        <listitem>
-         <para>Don't read either <filename>./.ghci</filename> or
-         <filename>$HOME/.ghci</filename> when starting up.</para>
+         <para>Don't read either <filename>./.ghci</filename> or the
+          other startup files when starting up.</para>
        </listitem>
       </varlistentry>
       <varlistentry>
@@ -2604,8 +2687,8 @@ Prelude> :set -fno-glasgow-exts
           <indexterm><primary><option>-read-dot-ghci</option></primary></indexterm>
         </term>
        <listitem>
-         <para>Read <filename>.ghci</filename> and
-         <filename>$HOME/.ghci</filename>.  This is normally the
+         <para>Read <filename>./.ghci</filename> and the other
+          startup files (see above).  This is normally the
          default, but the <option>-read-dot-ghci</option> option may
          be used to override a previous
          <option>-ignore-dot-ghci</option> option.</para>