「48時間でSchemeを書こう/練習問題の解答」の版間の差分
削除された内容 追加された内容
マークアップの改善 |
|||
1 行
=
<li>
<syntaxhighlight lang="haskell">
import System
9 ⟶ 10行目:
putStrLn ("Hello, " ++ args !! 0 ++ " " ++ args !! 1)
</syntaxhighlight>
</li>
<li>
<syntaxhighlight lang="haskell">
import System
20 ⟶ 22行目:
<code>$</code>演算子によって括弧の数を減らしています。最後の行は<code>$</code>を使わずに<code>print ((read (args !! 0)) + (read $ args !! 1))</code>とも書けます。
</li>
<li>
<syntaxhighlight lang="haskell">
import System
30 ⟶ 33行目:
putStrLn $ "あなたの名前は" ++ name ++ "ですね!"
</syntaxhighlight>
</li>
</ol>
= 練習問題2 =
51 ⟶ 56行目:
</ol>
</li>
▲</ol>
<li>
We need to create a new parser action that accepts a backslash followed by either another backslash or a doublequote. This action needs to return only the second character.
<syntaxhighlight lang="haskell">
escapedChars = do char '\\' -- a backslash </syntaxhighlight>
Once that is done, we need to make some changes to parseString.
69 ⟶ 74行目:
char '"'
return $ String x
</li>
<li>
escapedChars :: Parser Char
escapedChars = do char '\\'
81 ⟶ 86行目:
'r' -> '\r'
't' -> '\t'
</li>
<li>
First, it is necessary to change the definition of symbol.
147 ⟶ 152行目:
bin2dig' old xs
</li>
<li>
data LispVal = Atom String
| List [LispVal]
178 ⟶ 184行目:
<|> try parseBool -- these can all start with the hash char
<|> try parseCharacter
</li>
<li>
A possible solution for floating point numbers:
193 ⟶ 199行目:
| Float Double
to the LispVal type.
</li>
<li>
'''Ratio''', using Haskell's Ratio type:
229 ⟶ 235行目:
| Complex (Complex Double)
to the LispVal type.
</li>
</ol>
==Section 4 - Recursive Parsers: Adding lists, dotted lists, and quoted datums==
|