From 43efa562f5467917746fa1c0dd014a56457a5770 Mon Sep 17 00:00:00 2001 From: "Yann Esposito (Yogsototh)" Date: Sat, 4 Mar 2017 22:15:00 +0100 Subject: [PATCH] binary numeric tests fuctions --- src/Lish/InternalCommands.hs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Lish/InternalCommands.hs b/src/Lish/InternalCommands.hs index 828f329..dbdea0b 100644 --- a/src/Lish/InternalCommands.hs +++ b/src/Lish/InternalCommands.hs @@ -21,6 +21,7 @@ toArg (Atom x) = do Just (Str s) -> s _ -> toS x toArg (Str s) = return $ Just $ toS s +toArg (Num i) = return . Just . toS . show $ i toArg (Stream (Just h)) = lift $ fmap (Just . Text.strip .toS) (hGetContents h) toArg _ = return $ Nothing @@ -106,7 +107,11 @@ toWaitingStream _ = return Void equal :: ReduceUnawareCommand equal (x:y:[]) = return (Bool (x == y)) -equal args = evalErr $ "= need two args, got" <> (toS (show args)) +equal args = evalErr $ "= need two args, got " <> (toS (show args)) + +bintest :: (Integer -> Integer -> Bool) -> ReduceUnawareCommand +bintest f ((Num x):(Num y):[]) = return $ Bool (f x y) +bintest _ args = evalErr $ "bin test need two numbers got " <> (toS (show args)) toStrictCmd :: ReduceUnawareCommand -> Command toStrictCmd f reducer sexps = do @@ -154,6 +159,11 @@ strictCommands = [ ("prn", prn) , ("*",binop (*)) , ("/",binop div) , ("^",binop (^)) + -- bin numeric test + , ("<",bintest (<)) + , ("<=",bintest (<=)) + , (">",bintest (>)) + , (">=",bintest (>=)) -- boolean bin ops , ("and", bbinop (&&)) , ("or", bbinop (||))