SICP
SICPで反復が理解できてなかったので、有名なお二人のブログでの例を利用してプロセスを視覚化してみた 参考サイト 関数型言語の勉強にSICPを読もう - (7) 1章 - 反復をマスターしたいけど・・・ - Higepon’s blog 404 Blog Not Found:Recursion vs. Iterati…
1.2.2 Tree Recursionの Figure 1.5: The tree-recursive process generated in computing (fib 5).(図 1.5: 計算で生成された木構造再帰プロセス(fib5)) の図を自分的にわかりやすいようreturn(RETN)を追加してみた。 *1一応schemeのコードとプロセス(前…
SICP 1.2.2 Tree Recursion (木階層再帰?)のFigure 1.5のあたりを Pythonでやってみた 視覚的にプロセスがわかるよう、有名どころのここを参考にtraceを使ってみた。(slibはMacportsで簡単にインスコロールできた) Pythonでtraceみたいのできないのかな…
Structure and Interpretation of Computer Programs sec_1.1.8 #1.1.8 Procedures as Black-Box Abstractions(ブラックボックス抽象化の手続き) #Internal definitions and block structure(内在的な定義とブロック構造) #平方根の例 def square(x): re…
SICP 1.2 Procedures and the Processes They Generate(手続きと生成プロセス) ## 1.2.1 Linear Recursion and Iteration(線形の再帰と反復) # 図 1.3:再帰の例 def factorial(n): if n == 1: return 1 return n * factorial(n - 1) print factorial(6) …
Exercise 1.8. Newton's method for cube roots is based on the fact that if y is an approximation to the cube root of x, then a better approximation is given by the value (練習 1.8 ニュートン法において立方根は、yがxの立方根の近似値だとした…
#1.1.7 Example: Square Roots by Newton's Method #(1.1.7 例:ニュートン法による平方根) def square(x): return x * x def sqrt_iter (guess, x): if good_enough(guess, x): return guess else: return sqrt_iter(improve(guess,x), x) def improve(gues…
SICP(和訳:計算機プログラムの構造と解釈)の1.1.6 Conditional Expressions and PredicatesのExercise 1.3.をPythonでやってみた (元はschemeの例題) #Exercise 1.3.Define a procedure that takes three numbers as arguments and returns the sum of …
macport でGaucheをインストールしようとしたらエラーがでたりしたのでメモ。 (会社のmacはすんなり入ったのに自宅のiBookではだめだった。なぜかしらん)とりあえあず以下のようなエラーがでた。 sudo port install gauche : ---> Fetching gdbm ---> Atte…