Fixed spelling error in compiler/ghci/InteractiveUI.hs and docs/users_guide/ghci.xml
[ghc-hetmet.git] / docs / users_guide / ghci.xml
index e79fb46..f9efe34 100644 (file)
@@ -49,6 +49,8 @@ Prelude>
    :browse [*]<module>         display the names defined by <module>
    :cd <dir>                   change directory to <dir>
    :def <cmd> <expr>           define a command :<cmd>
+   :edit <file>                edit file
+   :edit                       edit last module
    :help, :?                   display this list of commands
    :info [<name> ...]          display information about the given names
    :load <filename> ...        load module(s) and their dependents
@@ -60,12 +62,13 @@ Prelude>
    :set args <arg> ...         set the arguments returned by System.getArgs
    :set prog <progname>        set the value returned by System.getProgName
    :set prompt <prompt>        set the prompt used in GHCi
+   :set editor <cmd>        set the command used for :edit
 
    :show modules               show the currently loaded modules
    :show bindings              show the current bindings made at the prompt
 
    :ctags [<file>]             create tags file for Vi (default: "tags")
-   :etags [<file>]             create tags file for Emacs (defauilt: "TAGS")
+   :etags [<file>]             create tags file for Emacs (default: "TAGS")
    :type <expr>                show the type of <expr>
    :kind <type>                show the kind of <type>
    :undef <cmd>                undefine user-defined command :<cmd>
@@ -402,7 +405,7 @@ hello
 </screen>
 </para></sect2>
 
-    <sect2>
+    <sect2 id="ghci-stmts">
       <title>Using <literal>do-</literal>notation at the prompt</title>
       <indexterm><primary>do-notation</primary><secondary>in GHCi</secondary></indexterm>
       <indexterm><primary>statements</primary><secondary>in GHCi</secondary></indexterm>
@@ -444,7 +447,13 @@ Prelude>
              <literal>Show</literal></para>
          </listitem>
        </itemizedlist>
-      </para>
+      The automatic printing of binding results can be supressed with
+      <option>:set -fno-print-bind-result</option> (this does not
+      supress printing the result of non-binding statements).
+      <indexterm><primary><option>-fno-print-bind-result</option></primary></indexterm><indexterm><primary><option>-fprint-bind-result</option></primary></indexterm>.
+      You might want to do this to prevent the result of binding
+      statements from being fully evaluated by the act of printing
+      them, for example.</para>
 
       <para>Of course, you can also bind normal non-IO expressions
       using the <literal>let</literal>-statement:</para>
@@ -604,6 +613,12 @@ Prelude IO>
       behaves in the same way for expressions typed at the
       prompt.</para>
 
+      <para>
+        Hint: GHCi will tab-complete names that are in scope; for
+        example, if you run GHCi and type <literal>J&lt;tab&gt;</literal>
+        then GHCi will expand it to <literal>Just </literal>.
+      </para>
+
       <sect3>
        <title>Qualified names</title>
 
@@ -873,10 +888,8 @@ $ ghci -lm
     <para>GHCi commands all begin with
     &lsquo;<literal>:</literal>&rsquo; and consist of a single command
     name followed by zero or more parameters.  The command name may be
-    abbreviated, as long as the abbreviation is not ambiguous.  All of
-    the builtin commands, with the exception of
-    <literal>:unset</literal> and <literal>:undef</literal>, may be
-    abbreviated to a single letter.</para>
+    abbreviated, with ambiguities being resolved in favour of the more
+    commonly used commands.</para>
 
     <variablelist>
       <varlistentry>
@@ -1003,6 +1016,22 @@ Prelude> :. cmds.ghci
 
       <varlistentry>
        <term>
+          <literal>:edit <optional><replaceable>file</replaceable></optional></literal>
+          <indexterm><primary><literal>:edit</literal></primary></indexterm>
+        </term>
+       <listitem>
+         <para>Opens an editor to edit the file
+         <replaceable>file</replaceable>, or the most recently loaded
+         module if <replaceable>file</replaceable> is omitted.  The
+         editor to invoke is taken from the <literal>EDITOR</literal>
+         environment variable, or a default editor on your system if
+         <literal>EDITOR</literal> is not set.  You can change the
+         editor using <literal>:set editor</literal>.</para>
+       </listitem>
+      </varlistentry>
+
+      <varlistentry>
+       <term>
           <literal>:help</literal>
           <indexterm><primary><literal>:help</literal></primary></indexterm>
         </term>
@@ -1074,6 +1103,38 @@ Prelude> :. cmds.ghci
 
       <varlistentry>
        <term>
+          <literal>:main <replaceable>arg<subscript>1</subscript></replaceable> ... <replaceable>arg<subscript>n</subscript></replaceable></literal>
+          <indexterm><primary><literal>:main</literal></primary></indexterm>
+        </term>
+        <listitem>
+          <para>
+            When a program is compiled and executed, it can use the
+            <literal>getArgs</literal> function to access the
+            command-line arguments.
+            However, we cannot simply pass the arguments to the
+            <literal>main</literal> function while we are testing in ghci,
+            as the <literal>main</literal> function doesn't take its
+            directly.
+          </para>
+
+          <para>
+            Instead, we can use the <literal>:main</literal> command.
+            This runs whatever <literal>main</literal> is in scope, with
+            any arguments being treated the same as command-line arguments,
+            e.g.:
+          </para>
+
+<screen>
+Prelude> let main = System.Environment.getArgs >>= print
+Prelude> :main foo bar
+["foo","bar"]
+</screen>
+
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+       <term>
           <literal>:module <optional>+|-</optional> <optional>*</optional><replaceable>mod<subscript>1</subscript></replaceable> ... <optional>*</optional><replaceable>mod<subscript>n</subscript></replaceable></literal>
           <indexterm><primary><literal>:module</literal></primary></indexterm>
         </term>
@@ -1136,6 +1197,16 @@ Prelude> :. cmds.ghci
 
       <varlistentry>
        <term>
+           <literal>:set</literal> <literal>editor</literal> <replaceable>cmd</replaceable>
+        </term>
+       <listitem>
+         <para>Sets the command used by <literal>:edit</literal> to
+         <replaceable>cmd</replaceable>.</para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+       <term>
            <literal>:set</literal> <literal>prog</literal> <replaceable>prog</replaceable>
            <indexterm><primary><literal>:set prog</literal></primary></indexterm>
         </term>