From: Samir Benmendil Date: Sun, 14 Jan 2018 00:24:21 +0000 (+0000) Subject: Handle boolean constants X-Git-Url: https://git.rmz.io/my-scheme.git/commitdiff_plain/081ba0cc6439a82a508100a59d6fa5dba80609d9?ds=inline Handle boolean constants Turns out that Scheme defines `#t` and `#f` to be `true` and `false`. `let` is used to devife a new symbol `atom` which is a String. `case...of` matches the literals and constructs a `LispVal` of the appropriate type and value. `_` is a match all token. --- diff --git a/app/Main.hs b/app/Main.hs index 7c987ce..6fcf667 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -26,7 +26,11 @@ parseAtom :: Parser LispVal parseAtom = do a <- letter <|> symbol b <- many (letter <|> digit <|> symbol) - return $ Atom (a:b) + let atom = a:b + return $ case atom of + "#t" -> Bool True + "#f" -> Bool False + _ -> Atom atom readExpr :: String -> String readExpr input = case parse (spaces >> symbol) "lisp" input of