egison 3.2.10 → 3.2.11
raw patch · 4 files changed
+40/−9 lines, 4 filesdep +textdep −mysqlPVP ok
version bump matches the API change (PVP)
Dependencies added: text
Dependencies removed: mysql
API changes (from Hackage documentation)
Files
- egison.cabal +4/−2
- hs-src/Language/Egison/Primitives.hs +30/−3
- lib/core/database.egi +2/−2
- lib/core/string.egi +4/−2
egison.cabal view
@@ -1,5 +1,5 @@ Name: egison-Version: 3.2.10+Version: 3.2.11 Synopsis: Programming language with non-linear pattern-matching against unfree data types Description: An interpreter for Egison, the programming langugage that realized non-linear pattern-matching with unfree data types. With Egison, you can represent pattern-matching with unfree data types intuitively,@@ -26,7 +26,9 @@ location: https://github.com/egisatoshi/egison3.git Library- Build-Depends: base >= 4.0 && < 5, array, random, containers, unordered-containers, haskeline, transformers, mtl, parsec >= 3.0, directory, ghc, ghc-paths, strict-io, bytestring, mysql+ Build-Depends: base >= 4.0 && < 5, array, random, containers, unordered-containers, haskeline, transformers, mtl, parsec >= 3.0, directory, ghc, ghc-paths, strict-io, bytestring, text+-- , direct-sqlite -- for 'egison-sqlite'+-- , mysql -- for 'egison-mysql' Hs-Source-Dirs: hs-src Exposed-Modules: Language.Egison
hs-src/Language/Egison/Primitives.hs view
@@ -15,11 +15,14 @@ import qualified Data.Sequence as Sq import System.IO.Unsafe-import qualified Database.MySQL.Base as MySQL import Data.ByteString (ByteString) import qualified Data.ByteString as BS import qualified Data.ByteString.Char8 as BC+import qualified Data.Text as T +--import qualified Database.SQLite3 as SQLite -- for 'egison-sqlite'+--import qualified Database.MySQL.Base as MySQL -- for 'egison-mysql'+ import Control.Monad import Language.Egison.Types@@ -144,7 +147,8 @@ , ("assert", assert) , ("assert-equal", assertEqual) - , ("pure-mysql", pureMySQL)+-- , ("pure-sqlite", pureSQLite) -- for 'egison-sqlite'+-- , ("pure-mysql", pureMySQL) -- for 'egison-mysql' ] integerUnaryOp :: (Integer -> Integer) -> PrimitiveFunc@@ -340,8 +344,30 @@ then return $ Bool True else throwError $ Assertion $ show label ++ "\n expected: " ++ show expected ++ "\n but found: " ++ show actual-+{-- -- for 'egison-sqlite'+pureSQLite :: PrimitiveFunc+pureSQLite = (liftError .) $ twoArgs $ \val val' -> do+ dbName <- fromStringValue val+ qStr <- fromStringValue val'+ let ret = unsafePerformIO $ query' (T.pack dbName) $ T.pack qStr+ return $ Collection $ Sq.fromList $ map (\r -> Tuple (map makeStringValue r)) ret+ where+ query' :: T.Text -> T.Text -> IO [[String]]+ query' dbName q = do+ db <- SQLite.open dbName+ rowsRef <- newIORef []+ SQLite.execWithCallback db q (\_ _ mcs -> do+ row <- forM mcs (\mcol -> case mcol of+ Just col -> return $ T.unpack col+ Nothing -> return "null")+ rows <- readIORef rowsRef+ writeIORef rowsRef (row:rows))+ SQLite.close db+ ret <- readIORef rowsRef+ return $ reverse ret+--} +{-- -- for 'egison-mysql' pureMySQL :: PrimitiveFunc pureMySQL = (liftError .) $ twoArgs $ \val val' -> do dbName <- fromStringValue val@@ -365,6 +391,7 @@ Nothing -> return "null") rows' <- fetchAllRows ret return $ row':rows'+--} -- -- IO Primitives
lib/core/database.egi view
@@ -21,7 +21,7 @@ ;; (define $simple-select (lambda [$whats $table-name $wheres]- {@"select " @(concat (insert-between whats ", ")) @" from " @table-name @" " @(simple-where wheres)}))+ {@"select " @(intercalate "," whats) @" from " @table-name @" " @(simple-where wheres)})) (define $simple-where (lambda [$wheres]@@ -32,4 +32,4 @@ {{@key @" = " @val} @(loop-fn rs)}]}))]} (match (loop-fn wheres) (list string) {[<nil> ""]- [<cons $wc $wcs> {@"where " @(concat (insert-between {wc @wcs} " and "))}]}))))+ [<cons $wc $wcs> {@"where " @(intercalate " and " {wc @wcs})}]}))))
lib/core/string.egi view
@@ -2,9 +2,11 @@ ;;; String.egi ;;; -(define $insert-between- (lambda [$ws $in]+(define $intersperse+ (lambda [$in $ws] (foldl (lambda [$s1 $s2] {@s1 in s2}) {(car ws)} (cdr ws))))++(define $intercalate (compose intersperse concat)) (define $palindrome? (lambda [$str]