X-Git-Url: https://git.rmz.io/my-scheme.git/blobdiff_plain/fabc3d8bdaef310b2f18bc53735ad7ee53518822..refs/heads/master:/app/Main.hs?ds=sidebyside diff --git a/app/Main.hs b/app/Main.hs index 1495605..78f37ea 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -11,7 +11,6 @@ data LispVal = Atom String | String String | Character Char | Bool Bool - deriving Show symbol :: Parser Char symbol = oneOf "!#$%&|*+-/:<=>?@^_~" @@ -96,14 +95,20 @@ readExpr input = case parse parseExpr "lisp" input of Left err -> "No match: " ++ show err Right val -> "Found value: " ++ showVal val +instance Show LispVal where show = showVal showVal :: LispVal -> String showVal (Atom atom) = atom +showVal (List list) = "(" ++ unwordsList list ++ ")" +showVal (DottedList head tail) = "(" ++ unwordsList head ++ " . " ++ showVal tail ++ ")" showVal (Number n) = show n showVal (String str) = "\"" ++ str ++ "\"" showVal (Character c) = "'" ++ [c] ++ "'" showVal (Bool True) = "#t" showVal (Bool False) = "#f" +unwordsList :: [LispVal] -> String +unwordsList = unwords . map showVal + main :: IO () main = do args <- getLine