egison-tutorial 3.7.14 → 3.9.3
raw patch · 3 files changed
+35/−10 lines, 3 filesdep ~egisonsetup-changed
Dependency ranges changed: egison
Files
- Main.hs +32/−6
- Setup.hs +0/−2
- egison-tutorial.cabal +3/−2
Main.hs view
@@ -2,10 +2,11 @@ import Prelude hiding (catch) import Control.Exception ( AsyncException(..), catch )-import Control.Monad.Error+import Control.Monad.Except import Data.Version import Data.List+import Text.Regex.Posix import System.IO import System.Environment@@ -15,8 +16,10 @@ import System.Console.GetOpt import System.Exit (ExitCode (..), exitWith, exitFailure) -import Language.Egison+import Language.Egison hiding (optShowVersion, optPrompt)+import qualified Language.Egison.Types as ET import Language.Egison.Util+import qualified Language.Egison.Parser as Parser import qualified Paths_egison_tutorial as P main :: IO ()@@ -41,7 +44,7 @@ Options {optShowHelp = True} -> printHelp Options {optShowVersion = True} -> printVersionNumber Options {optPrompt = prompt} -> do- env <- initialEnv+ env <- initialEnv ET.defaultOption case nonOpts of [] -> showBanner >> repl env prompt _ -> printHelp@@ -163,6 +166,29 @@ putStrLn "Invalid input!" getNumber n +-- |Get Egison expression from the prompt. We can handle multiline input.+getEgisonExprOrNewLine :: Options -> InputT IO (Either (Maybe String) (String, EgisonTopExpr))+getEgisonExprOrNewLine opts = getEgisonExprOrNewLine' opts ""++getEgisonExprOrNewLine' :: Options -> String -> InputT IO (Either (Maybe String) (String, EgisonTopExpr))+getEgisonExprOrNewLine' opts prev = do+ mLine <- case prev of+ "" -> getInputLine $ optPrompt opts+ _ -> getInputLine $ replicate (length $ optPrompt opts) ' '+ case mLine of+ Nothing -> return $ Left Nothing+ Just [] -> return $ Left $ Just ""+ Just line -> do+ let input = prev ++ line+ let parsedExpr = Parser.parseTopExpr input+ case parsedExpr of+ Left err | show err =~ "unexpected end of input" ->+ getEgisonExprOrNewLine' opts $ input ++ "\n"+ Left err -> do+ liftIO $ print err+ getEgisonExprOrNewLine opts+ Right topExpr -> return $ Right (input, topExpr)+ repl :: Env -> String -> IO () repl env prompt = do section <- selectSection tutorial@@ -181,7 +207,7 @@ then liftIO $ putStrLn $ show content else return () home <- getHomeDirectory- input <- liftIO $ runInputT (settings home) $ getEgisonExprOrNewLine prompt+ input <- liftIO $ runInputT (settings home) $ getEgisonExprOrNewLine defaultOptions case input of Left Nothing -> do b <- yesOrNo "Do you want to quit?"@@ -198,7 +224,7 @@ then loop env contents True else loop env (content:contents) False Right (topExpr, _) -> do- result <- liftIO $ runEgisonTopExpr True env topExpr+ result <- liftIO $ runEgisonTopExpr ET.defaultOption env topExpr case result of Left err -> do liftIO $ putStrLn $ show err@@ -372,7 +398,7 @@ Content "A pattern whose form is \"(| p1 p2 ...)\" is called an or-pattern.\nAn or-pattern matches with the object, if the object matches one of the given patterns.\nIn the following sample, we enumerate prime triplets using it." ["(take 10 (match-all primes (list integer) [<join _ <cons $p <cons (& $m (| ,(+ p 2) ,(+ p 4))) <cons ,(+ p 6) _>>>> [p m (+ p 6)]]))"] ["What is the 20th prime triplet?"],- Content "Try to enumerate the first 8 prime quadruples whose form is (p, p+2, p+6, p+8) like \"{{[5 7 11 13] [11 13 17 19] ...}\"."+ Content "Try to enumerate the first 4 prime quadruples whose form is (p, p+2, p+6, p+8) like \"{{[5 7 11 13] [11 13 17 19] ...}\"." [] [], Content "This is the end of this section.\nPlease play freely or proceed to the next section.\nThank you for enjoying our tutorial!"
− Setup.hs
@@ -1,2 +0,0 @@-import Distribution.Simple-main = defaultMain
egison-tutorial.cabal view
@@ -1,5 +1,5 @@ Name: egison-tutorial-Version: 3.7.14+Version: 3.9.3 Synopsis: A tutorial program for the Egison programming language Description: A tutorial program for the Egison programming language. Egison is the programming langugage that realized non-linear pattern-matching against unfree data types.@@ -20,4 +20,5 @@ Executable egison-tutorial Main-is: Main.hs- Build-depends: egison >= 3.7.14, base >= 4.0 && < 5, array, containers, unordered-containers, haskeline, transformers, mtl, parsec >= 3.0, directory, ghc, ghc-paths, filepath, regex-posix, bytestring+ Build-depends: egison >= 3.9.3, base >= 4.0 && < 5, array, containers, unordered-containers, haskeline, transformers, mtl, parsec >= 3.0, directory, ghc, ghc-paths, filepath, regex-posix, bytestring+ Other-modules: Paths_egison_tutorial