「48時間でSchemeを書こう/練習問題の解答」の版間の差分
削除された内容 追加された内容
一部訳出 |
M →練習問題2: マークアップ |
||
95 行
First, it is necessary to change the definition of symbol.
<syntaxhighlight lang="haskell">
symbol = oneOf "!$%&|*+-/:<=>?@^_~" </syntaxhighlight>
This means that it is no longer possible to begin an atom with the hash character. This necessitates a different way of parsing #t and #f.
<syntaxhighlight lang="haskell">
parseBool :: Parser LispVal▼
x <- oneOf "tf"▼
x
return $ case x of
</syntaxhighlight>
This in turn requires us to make changes to parseExpr.
<syntaxhighlight lang="haskell">
parseExpr = parseAtom
<|> parseString▼
</syntaxhighlight>
parseNumber need to be changed to the following.
<syntaxhighlight lang="haskell">
parseNumber = do num <- parseDigital1 <|> parseDigital2 <|> parseHex <|> parseOct <|> parseBin </syntaxhighlight>
And the following new functions need to be added.
<syntaxhighlight lang="haskell">
parseDigital1 = do x <- many1 digit
▲ parseDigital2 = do try $ string "#d"
▲ x <- many1 digit
▲ (return . Number . read) x
</syntaxhighlight>
</li>
|