関数型言語の勉強にSICPを読もう - (56) 4章 - 超言語的抽象(220ページ) C++でSchemeインタプリタを作ろう4
手続き
「手続き作用はいずれでもない任意の合成式である」と書いてあっていいたい事は分かるのだけれど、C++でどう書いてよいか分からない。
きっとあとで思いつくに違いない。
cond
condは if で書けるよという話。
こんな感じでよいかな。なんとなく再帰で書いてみた。
fix me メソッドを公開(ぉ
Object* Cond::expand()
{
return expandInternal(clauses_->begin());
}
Object* Cond::expandInternal(Clauses::iterator it)
{
if (it == clauses_->end())
{
if (NULL != elseActions_)
{
return new Begin(elseActions_);
}
else
{
return new Number(0); // fix me
}
}
Clause* clause = *it;
return new SpecialIf(clause->first, new Begin(clause->second), expandInternal(it++));
}計算機プログラムの構造と解釈
posted with amazlet on 06.05.31
