]> git.rmz.io Git - my-scheme.git/commitdiff
Handle boolean constants
authorSamir Benmendil <me@rmz.io>
Sun, 14 Jan 2018 00:24:21 +0000 (00:24 +0000)
committerSamir Benmendil <me@rmz.io>
Sun, 14 Jan 2018 00:24:21 +0000 (00:24 +0000)
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

index 7c987cee50d96d97e445cc1b18756f845a47a24f..6fcf6675f175374d22b749097dc06142312b8400 100644 (file)
@@ -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