mirror of
https://github.com/zoriya/HAL.git
synced 2026-05-29 12:31:47 +00:00
Adding mod
This commit is contained in:
@@ -14,6 +14,10 @@ data Atom =
|
||||
AFalse |
|
||||
ANothing
|
||||
|
||||
_fromBool :: Bool -> Atom
|
||||
_fromBool True = ATrue
|
||||
_fromBool False = AFalse
|
||||
|
||||
newtype SExpr = SExpr [Statement]
|
||||
|
||||
instance Show Atom where
|
||||
|
||||
@@ -41,11 +41,6 @@ evalCdr [Expr expr] env = do
|
||||
evalCdr [Atom bad] _ = Left $ "**Error: " ++ show bad ++ " is not a pair.**"
|
||||
evalCdr _ _ = Left "**Error: incorect argument count in cdr**"
|
||||
|
||||
|
||||
_fromBool :: Bool -> Atom
|
||||
_fromBool True = ATrue
|
||||
_fromBool False = AFalse
|
||||
|
||||
evalEq :: [Statement] -> LispEnv -> Either String (Atom, LispEnv)
|
||||
evalEq [Atom (AInt f), Atom (AInt s)] env = Right (_fromBool (f == s), env)
|
||||
evalEq [Atom (ASymbol f), Atom (ASymbol s)] env = Right (_fromBool (f == s), env)
|
||||
|
||||
+16
-2
@@ -8,7 +8,8 @@ mathEnv = [
|
||||
("-", ABuiltin "-" evalMinus),
|
||||
("*", ABuiltin "*" evalMult),
|
||||
("div", ABuiltin "div" evalDiv),
|
||||
("mod", ABuiltin "mod" evalMod)
|
||||
("mod", ABuiltin "mod" evalMod),
|
||||
("<", ABuiltin "<" evalLessThan)
|
||||
]
|
||||
|
||||
evalPlus :: [Statement] -> LispEnv -> Either String (Atom, LispEnv)
|
||||
@@ -72,4 +73,17 @@ evalMod [Expr expr, other] env = do
|
||||
evalMod [other, Expr expr] env = do
|
||||
(res, nEnv) <- evalS expr env
|
||||
evalMod [other, Atom res] nEnv
|
||||
evalMod _ _ = Left "**Error: Invalid arguments in mod.**"
|
||||
evalMod _ _ = Left "**Error: Invalid arguments in mod.**"
|
||||
|
||||
evalLessThan :: [Statement] -> LispEnv -> Either String (Atom, LispEnv)
|
||||
evalLessThan [Atom (AInt f), Atom (AInt s)] env = Right (_fromBool (f < s), env)
|
||||
evalLessThan [Atom (AFloat f), Atom (AFloat s)] env = Right (_fromBool (f < s), env)
|
||||
evalLessThan [Atom (AFloat f), Atom (AInt s)] env = Right (_fromBool (f < fromIntegral s), env)
|
||||
evalLessThan [Atom (AInt f), Atom (AFloat s)] env = Right (_fromBool (fromIntegral f < s), env)
|
||||
evalLessThan [Expr expr, other] env = do
|
||||
(res, nEnv) <- evalS expr env
|
||||
evalLessThan [Atom res, other] nEnv
|
||||
evalLessThan [other, Expr expr] env = do
|
||||
(res, nEnv) <- evalS expr env
|
||||
evalLessThan [other, Atom res] nEnv
|
||||
evalLessThan _ _ = Left "**Error: Invalid arguments in <.**"
|
||||
Reference in New Issue
Block a user