packages feed

egison-tutorial 3.3.2 → 3.3.3

raw patch · 2 files changed

+72/−44 lines, 2 filesdep ~egison

Dependency ranges changed: egison

Files

Main.hs view
@@ -24,6 +24,20 @@           let (actions, nonOpts, _) = getOpt Permute options args           let opts = foldl (flip id) defaultOptions actions           case opts of+            Options {optShowSections = True} -> putStrLn $ show tutorial+            Options {optSection = Just sn, optSubSection = Just ssn} -> do+              let sn' = (read sn) :: Int+              let ssn' = (read ssn) :: Int+              let ret = case tutorial of+                          Tutorial ss ->+                            if 0 < sn' && sn' <= length ss +                              then case nth sn' ss of+                                     Section _ cs ->+                                       if 0 < ssn' && ssn' <= length cs +                                         then showContent $ nth ssn' cs+                                         else "error: content out of range"+                              else "error: section out of range"+              putStrLn ret             Options {optShowHelp = True} -> printHelp             Options {optShowVersion = True} -> printVersionNumber             Options {optPrompt = prompt} -> do@@ -35,14 +49,20 @@ data Options = Options {     optShowVersion :: Bool,     optShowHelp :: Bool,-    optPrompt :: String+    optPrompt :: String,+    optShowSections :: Bool,+    optSection :: Maybe String,+    optSubSection :: Maybe String     }  defaultOptions :: Options defaultOptions = Options {     optShowVersion = False,     optShowHelp = False,-    optPrompt = "> "+    optPrompt = "> ",+    optShowSections = False,+    optSection = Nothing,+    optSubSection = Nothing     }  options :: [OptDescr (Options -> Options)]@@ -56,7 +76,18 @@   Option ['p'] ["prompt"]     (ReqArg (\prompt opts -> opts {optPrompt = prompt})             "String")-    "set prompt string"+    "set prompt string",+  Option ['l'] ["list"]+    (NoArg (\opts -> opts {optShowSections = True}))+    "show section list",+  Option ['s'] ["section"]+    (ReqArg (\sn opts -> opts {optSection = Just sn})+            "String")+    "set section number",+  Option ['c'] ["subsection"]+    (ReqArg (\ssn opts -> opts {optSubSection = Just ssn})+            "String")+    "set subsection number"   ]  printHelp :: IO ()@@ -130,10 +161,10 @@     ('2':_) -> return 2     ('3':_) -> return 3     ('4':_) -> return 4-    ('5':_) -> return 5-    ('6':_) -> return 6-    ('7':_) -> return 7-    ('9':_) -> return 9+--    ('5':_) -> return 5+--    ('6':_) -> return 6+--    ('7':_) -> return 7+--    ('9':_) -> return 9     _ -> do       putStrLn "Invalid input!"       getNumber n@@ -273,6 +304,9 @@     ],   Section "Basics of functional programming"    [+    Content "We can define a function. Let's define a function and test it."+     ["(define $f (lambda [$x] (+ x 1)))", "(f 10)", "(define $g (lambda [$x $y] (* x y)))", "(g 10 20)", "(define $sum (lambda [$n] (foldl + 0 (take n nats))))", "(sum 10)"]+     ["Try to define a 'fact' function."],     Content "We can compare numbers using functions that return '#t' or '#f'.\n'#t' means the true.\n#f means the false.\nFunctions that return '#t' or '#f' are called \"predicates\"."      ["(eq? 1 1)", "(gt? 1 1)", "(lt? 1 1)",  "(gte? 1 1)", "(lte? 1 1)"]      [],@@ -284,7 +318,7 @@      [],     Content "With the 'filter' function, we can extract all elements that satisfy the predicate.\n'We extract all prime numbers that are congruent to 1 modulo 4."      ["(take 100 (filter (lambda [$p] (eq? (modulo p 4) 1)) primes))", "(take 200 (filter (lambda [$p] (eq? (modulo p 4) 1)) primes))"]-     [],+     ["Try to enumerate the first 100 primes that are congruent to 3 modulo 4."],     Content "We combine numbers using '[]'.\nThese things are called 'tuples'."      ["[1 2]", "[1 2 3]"]      [],@@ -304,25 +338,7 @@      []      []     ],-  Section "Define your own functions"-   [-    Content "We can define a function. Let's define a function and test it."-     ["(define $f (lambda [$x] (+ x 1)))", "(f 10)", "(define $g (lambda [$x $y] (* x y)))", "(g 10 20)"]-     [],-    Content "Let's try 'if' expressions."-     ["(if #t 1 2)", "(if #f 1 2)", "(let {[$x 10]} (if (eq? x 10) 1 2))"]-     [],-    Content "Using 'define' and 'if', we can write recursive functions as follow."-     ["(define $your-take (lambda [$n $xs] (if (eq? n 0) {} {(car xs) @(your-take (- n 1) (cdr xs))})))", "(your-take 10 nats)"]-     ["Try to write a 'your-while' function."],-    Content "Try to write a 'your-map' function.\nWe may need 'empty?' function inside 'your-map' function."-     ["(empty? {})", "(empty? {1 2 3})"]-     [],-    Content "We can view all library functions on collections at \"http://www.egison.org/libraries/core/collection.html\"."-     []-     []-    ],-  Section "Basic of pattern-matching"+  Section "Basics of pattern-matching"    [     Content "We can do pattern-matching against multisets."      ["(match-all {1 2 3} (multiset integer) [<cons $x $xs> [x xs]])"]@@ -375,20 +391,32 @@     Content "We've prepared the Egison cheat sheet here. It covers everything in this tutorial. Please check it!.\n\"http://www.egison.org/cheatsheet.html\"."      []      []-    ],-  Section "Writing scripts in Egison"-   [-    Content "Let's write a famous Hello world program in Egison.\nTry the following expression.\nIt is evaluated to the 'io-function'.\nTo execute an io-function, we use 'io' primitive as follow."-     ["(io (print \"Hello, world!\"))"]-     [],-    Content "We can execute multiple io-functions in sequence as follow.\nThe io-functions is executed from the head."-     ["(io (do {[(print \"a\")] [(print \"b\")] [(print \"c\")]} []))", "(io (do {[(write-string \"Type your name: \")] [(flush)] [$name (read-line)] [(print {@\"Hello, \" @name @\"!\"})]} []))"]-     [],-    Content "The following is a hello world program in Egison.\nTry to create a file with the following content and save it as \"hello.egi\", and execute it in the terminal as '% egison hello.egi'\n"-     ["(define $main (lambda [$args] (print \"Hello, world!\")))"]-     [],-    Content "That's all. Thank you for finishing our tutorail! Did you enjoy it?\nIf you got into Egison programming. I'd like you to try Rosseta Code.\nThere are a lot of interesting problems.\n\n  http://rosettacode.org/wiki/Category:Egison"-     []-     []     ]   ]+--  Section "Define your own functions"+--   [+--    Content "Let's try 'if' expressions."+--     ["(if #t 1 2)", "(if #f 1 2)", "(let {[$x 10]} (if (eq? x 10) 1 2))"]+--     [],+--    Content "Using 'define' and 'if', we can write recursive functions as follow."+--     ["(define $your-take (lambda [$n $xs] (if (eq? n 0) {} {(car xs) @(your-take (- n 1) (cdr xs))})))", "(your-take 10 nats)"]+--     ["Try to write a 'your-while' function."],+--    Content "Try to write a 'your-map' function.\nWe may need 'empty?' function inside 'your-map' function."+--     ["(empty? {})", "(empty? {1 2 3})"]+--     []+--  Section "Writing scripts in Egison"+--   [+--    Content "Let's write a famous Hello world program in Egison.\nTry the following expression.\nIt is evaluated to the 'io-function'.\nTo execute an io-function, we use 'io' primitive as follow."+--     ["(io (print \"Hello, world!\"))"]+--     [],+--    Content "We can execute multiple io-functions in sequence as follow.\nThe io-functions is executed from the head."+--     ["(io (do {[(print \"a\")] [(print \"b\")] [(print \"c\")]} []))", "(io (do {[(write-string \"Type your name: \")] [(flush)] [$name (read-line)] [(print {@\"Hello, \" @name @\"!\"})]} []))"]+--     [],+--    Content "The following is a hello world program in Egison.\nTry to create a file with the following content and save it as \"hello.egi\", and execute it in the terminal as '% egison hello.egi'\n"+--     ["(define $main (lambda [$args] (print \"Hello, world!\")))"]+--     [],+--    Content "That's all. Thank you for finishing our tutorail! Did you enjoy it?\nIf you got into Egison programming. I'd like you to try Rosseta Code.\nThere are a lot of interesting problems.\n\n  http://rosettacode.org/wiki/Category:Egison"+--     []+--     []+--    ]+--  ]
egison-tutorial.cabal view
@@ -1,5 +1,5 @@ Name:                egison-tutorial-Version:             3.3.2+Version:             3.3.3 Synopsis:            A tutorial program for the programming language Egison Description:         A tutorial program for the programming language Egison.                      Egison is the programming langugage that realized non-linear pattern-matching with unfree data types.@@ -20,4 +20,4 @@  Executable egison-tutorial   Main-is:             Main.hs-  Build-depends:       egison >= 3.3.2, base >= 4.0 && < 5, array, containers, unordered-containers, haskeline, transformers, mtl, parsec >= 3.0, directory, ghc, ghc-paths, filepath, regex-posix, strict-io, bytestring+  Build-depends:       egison >= 3.3.3, base >= 4.0 && < 5, array, containers, unordered-containers, haskeline, transformers, mtl, parsec >= 3.0, directory, ghc, ghc-paths, filepath, regex-posix, strict-io, bytestring