From: simonmar Date: Fri, 23 Mar 2001 15:25:30 +0000 (+0000) Subject: [project @ 2001-03-23 15:25:30 by simonmar] X-Git-Tag: Approximately_9120_patches~2329 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=0b98279386ba0e72d402e4fd7612cf30c74b395e;p=ghc-hetmet.git [project @ 2001-03-23 15:25:30 by simonmar] document :def and :undef --- diff --git a/ghc/docs/users_guide/ghci.sgml b/ghc/docs/users_guide/ghci.sgml index 35694a5..8e4836e 100644 --- a/ghc/docs/users_guide/ghci.sgml +++ b/ghc/docs/users_guide/ghci.sgml @@ -628,10 +628,55 @@ $ ghci -lm - :def + :def name expr :def - ToDo. + The command :def + name + expr defines a new GHCi command + :name, + implemented by the Haskell expression + expr, which must have type + String -> IO String. When + :name + args is typed at the + prompt, GHCi will run the expression + (name + args), take the + resulting String, and feed it back into + GHCi as a new sequence of commands. Separate commands in + the result must be separated by + ‘\n’. + + That's all a little confusing, so here's a few + examples. To start with, here's a new GHCi command which + doesn't take any arguments or produce any results, it just + outputs the current date & time: + + +Prelude> let date _ = Time.getClockTime >>= print >> return "" +Prelude> :def date date +Prelude> :date +Fri Mar 23 15:16:40 GMT 2001 + + + Here's an example of a command that takes an argument. + It's a re-implementation of :cd: + + +Prelude> let mycd d = Directory.setCurrentDirectory d >> return "" +Prelude> :def mycd mycd +Prelude> :mycd .. + + + Or I could define a simple way to invoke + “ghc --make Main” in the + current directory: + + +Prelude> :def make (\_ -> return ":! ghc --make Main") + + @@ -715,6 +760,16 @@ $ ghci -lm + :undef name + :undef + + Undefines the user-defined command + name (see :def + above). + + + + :unset option... :unset