packages feed

egison-tutorial 3.0.1 → 3.0.2

raw patch · 2 files changed

+54/−13 lines, 2 files

Files

Main.hs view
@@ -79,43 +79,62 @@  showBanner :: IO () showBanner = do-  putStrLn $ "Egison Tutorial for Version " ++ showVersion version ++ " (C) 2013 Satoshi Egi"+  putStrLn $ "Egison Tutorial for Version " ++ showVersion P.version ++ " (C) 2013 Satoshi Egi"   putStrLn $ "http://www.egison.org"   putStrLn $ "Welcome to Egison Tutorial!"  showFinishMessage :: IO () showFinishMessage = do-  putStrLn $ "You finished all tutorials!"+  putStrLn $ "You have finished this chapter."   putStrLn $ "Thank you!"-  putStrLn $ "Let's enjoy Egison!"  showByebyeMessage :: IO () showByebyeMessage = do   putStrLn $ "Leaving Egison Tutorial.\nByebye." +selectChapter :: [Chapter] -> IO [String]+selectChapter chaps = do+  putStrLn "Select a chapter to learn."+  foldM (\x chap -> do+          putStr $ "  " ++ show x ++ ": "+          putStrLn (fst chap)+          return (x + 1))+        1 chaps+  let m = length chaps+  putStr $ "(1-" ++ show m ++ "): "+  hFlush stdout+  input <- getLine+  let n = (read input :: Int)+  let chap = head $ drop (n - 1) chaps+  return (snd chap)+ askUser :: String -> IO Bool askUser question = do   putStr $ question-  putStr $ " (y/n): "+  putStr $ " (Y/n): "   hFlush stdout   input <- getLine   case input of+   [] -> return True    ('y':_) -> return True+   ('Y':_) -> return True    ('n':_) -> return False    _ -> askUser question  repl :: Env -> String -> IO () repl env prompt = do   home <- getHomeDirectory+  tutorials <- selectChapter chapters   liftIO (runInputT (settings home) $ loop env prompt "" tutorials True)   where     settings :: MonadIO m => FilePath -> Settings m     settings home = defaultSettings { historyFile = Just (home </> ".egison_tutorial_history") }     -    loop :: Env -> String -> String -> [Tutorial] -> Bool -> InputT IO ()-    loop _ _ _ [] _ = do+    loop :: Env -> String -> String -> [String] -> Bool -> InputT IO ()+    loop env prompt' _ [] _ = do       liftIO $ showFinishMessage-      return ()+      tutorials <- liftIO $ selectChapter chapters+      loop env prompt' "" tutorials True     loop env prompt' rest ts@(t:rs) True = do       liftIO $ putStrLn t       loop env prompt' rest ts False@@ -167,11 +186,29 @@             Right env' ->               loop env' prompt "" ts False         -type Tutorial = String+type Chapter = (String, [String]) -tutorials :: [Tutorial]-tutorials = [-  "You can do arithmetic operations with `+`, `-`, `*`, `div`. Try them as `(+ 1 2)`.",+chapters :: [Chapter]+chapters = [+  ("Basics", tutorialsForBasic),+  ("Pattern-Matching", tutorialsForPatternMatch)+  ]++tutorialsForBasic :: [String]+tutorialsForBasic = [+  "You can do arithmetic operations with `+`, `-`, `*`, `div`. Try them as `(+ 1 2)` or `(* 10 20)`.",   "You can bind a value to a variable with a `define` expression. Try it as `(define $x 10))`.",-  "You can get a value you binded to the variable. Try them as `x`."+  "You can get a value you binded to the variable. Try them as `x`.",+  "You can define a function. Try them as `(define $f [$x] (+ x 1))`.",+  "Try `if` expressions as `(if #t 1 2)` or `(if (eq? x 10) 1 2)`.",+  "Now, you can define a factorial function that gets a natural number 'n' and returns 'n * n-1 * n-2 * ... * 1'. Let's try!",+  "You can construct a collection with `{}`. Try it as `{1 2 3}`.",+  "The collection after `@` in a collection is called a subcollection. Try it as `{1 @{2 3} @{4 @{5}} 6}`.",+  "You can construct a tuple with `[]`. Try it as `[1 2]`.",+  "A tuple which consists of only one elment is equal with that element itself. Try it as `[1]` or `[[[1]]]`."+  ]++tutorialsForPatternMatch :: [String]+tutorialsForPatternMatch = [+  "You can do pattern-matching against multisets. Try it as `(match-all {1 2 3} (multiset integer) [<cons $x $xs> [x xs]])`."   ]
egison-tutorial.cabal view
@@ -1,5 +1,5 @@ Name:                egison-tutorial-Version:             3.0.1+Version:             3.0.2 Synopsis:            A Tutorial Program for The Programming Language Egison Description:         A tutorial program for the programming language Egison. Homepage:            http://www.egison.org@@ -10,6 +10,10 @@ Category:            Compilers/Interpreters Build-type:          Simple Cabal-version:       >=1.8++source-repository head+  type: git+  location: https://github.com/egisatoshi/egison-tutorial.git  Executable egison-tutorial   Main-is:             Main.hs