Talk:Write Yourself a Scheme in 48 Hours/Answers

Unquote only in quasiquotes?
Regarding Chapter 2, section 4, exercise 1: the current solution will also parse unquote and unquote-splice outside of the quasi-quote context. It seems to me that that's not correct, but I don't know of an elegant way to solve it. To solve it, I think parseQuasiquote shouldn't use parseExpr, but something else that is very similar. --- Nielius (discuss • contribs) 16:07, 20 April 2020 (UTC)

Does anybody have a better solution for 2/4/#3 ?

An alternative solution for bin2dig:

readBin :: Num a => ReadS a readBin = readInt 2 (\x -> x=='0' || x=='1') (\x -> case x of '0' -> 0; '1' -> 1) bin2dig x = fst $ readBin x !! 0

On exercise 2, people have yet to be introduced to print.

Exercise 2, section 4: "Add the following lines to parseExpr; before the parser for Lists and DottedLists." Adding the code directly there won't compile, I end up with this.

parseExpr :: Parser LispVal parseExpr = parseString <|> parseNumber <|> parseAtom <|> parseQuoted <|> parseBackquoted <|> parseUnquote <|> try (do string "#(" x <- parseVector char ')'                   return x)             <|> do char '('                    x <- try parseList <|> parseDottedList                    char ')' return x

GHC says 'parse error on input x'. Removing the try fixes it, but I'm not sure if that has the correct semantics.