From 0b98279386ba0e72d402e4fd7612cf30c74b395e Mon Sep 17 00:00:00 2001 From: simonmar Date: Fri, 23 Mar 2001 15:25:30 +0000 Subject: [PATCH] [project @ 2001-03-23 15:25:30 by simonmar] document :def and :undef --- ghc/docs/users_guide/ghci.sgml | 59 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) 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 -- 1.7.10.4