From 081ba0cc6439a82a508100a59d6fa5dba80609d9 Mon Sep 17 00:00:00 2001 From: Samir Benmendil Date: Sun, 14 Jan 2018 00:24:21 +0000 Subject: [PATCH] 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. --- app/Main.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 -- 2.48.1