http://mitpress.mit.edu/sicp/full-text/book/book.html
Structure and Interpretation of Computer Programs
を読んでます.
(階乗の計算.再帰を使うか繰り返しを使うかについて.再帰はメモリが足りなくなり桁数に制限あり、繰り返しだと繰り返しは制限無しのはず.linuxでのguileではそうだった)
ところがnewLispだとIterationでも12!まで.DrSchemeだと制限なし.(factorial 20000もできる.)
以下は1.2.1 Linear Recursion and Iterationからの抜粋です.
In contrasting iteration and recursion, we must be careful not to confuse the notion of a recursive process with the notion of a recursive procedure. When we describe a procedure as recursive, we are referring to the syntactic fact that the procedure definition refers (either directly or indirectly) to the procedure itself. But when we describe a process as following a pattern that is, say, linearly recursive, we are speaking about how the process evolves, not about the syntax of how a procedure is written. It may seem disturbing that we refer to a recursive procedure such as fact-iter as generating an iterative process. However, the process really is iterative: Its state is captured completely by its three state variables, and an interpreter need keep track of only three variables in order to execute the process.
(繰り返しと再帰を比べるときには、再帰的な過程と再帰的な手続きを混同してはならない.手続きを再帰的であるというときは手続きの定義で手続き自身を参照しているという構文上の事実をいう.一方過程を一次的に再帰的な形をとるというときは、過程がどのように起こるのかについて言うのであって構文上どのように書かれているかを言うのではない.fact-iterのような再帰的手続きについていうとき繰り返しの過程を生成するというと混乱するかもしれない.しかし、過程は実際に繰り返し的である.過程の状態は三つの状態変数によって完全に記録することができ、過程を実行ためインタプリータは三つの値を記録しておくだけでいい.)
One reason that the distinction between process and procedure may be confusing is that most implementations of common languages (including Ada, Pascal, and C) are designed in such a way that the interpretation of any recursive procedure consumes an amount of memory that grows with the number of procedure calls, even when the process described is, in principle, iterative.
(実行の過程と手続きの区別が混同される理由の一つはAda,Pascal,Cを含め多くの言語の実装が再帰的プロシージャーの呼び出しについて、たとえ実行の過程が繰り返し的にかかれていても、その呼び出しの回数に応じてメモリー消費量が増すようになっているためである.)
とあります.
newLispはschemeぽいですが、実装はこの点に関してはここでいうcommon language的.
Structure and Interpretation of Computer Programs
を読んでます.
(階乗の計算.再帰を使うか繰り返しを使うかについて.再帰はメモリが足りなくなり桁数に制限あり、繰り返しだと繰り返しは制限無しのはず.linuxでのguileではそうだった)
ところがnewLispだとIterationでも12!まで.DrSchemeだと制限なし.(factorial 20000もできる.)
以下は1.2.1 Linear Recursion and Iterationからの抜粋です.
In contrasting iteration and recursion, we must be careful not to confuse the notion of a recursive process with the notion of a recursive procedure. When we describe a procedure as recursive, we are referring to the syntactic fact that the procedure definition refers (either directly or indirectly) to the procedure itself. But when we describe a process as following a pattern that is, say, linearly recursive, we are speaking about how the process evolves, not about the syntax of how a procedure is written. It may seem disturbing that we refer to a recursive procedure such as fact-iter as generating an iterative process. However, the process really is iterative: Its state is captured completely by its three state variables, and an interpreter need keep track of only three variables in order to execute the process.
(繰り返しと再帰を比べるときには、再帰的な過程と再帰的な手続きを混同してはならない.手続きを再帰的であるというときは手続きの定義で手続き自身を参照しているという構文上の事実をいう.一方過程を一次的に再帰的な形をとるというときは、過程がどのように起こるのかについて言うのであって構文上どのように書かれているかを言うのではない.fact-iterのような再帰的手続きについていうとき繰り返しの過程を生成するというと混乱するかもしれない.しかし、過程は実際に繰り返し的である.過程の状態は三つの状態変数によって完全に記録することができ、過程を実行ためインタプリータは三つの値を記録しておくだけでいい.)
One reason that the distinction between process and procedure may be confusing is that most implementations of common languages (including Ada, Pascal, and C) are designed in such a way that the interpretation of any recursive procedure consumes an amount of memory that grows with the number of procedure calls, even when the process described is, in principle, iterative.
(実行の過程と手続きの区別が混同される理由の一つはAda,Pascal,Cを含め多くの言語の実装が再帰的プロシージャーの呼び出しについて、たとえ実行の過程が繰り返し的にかかれていても、その呼び出しの回数に応じてメモリー消費量が増すようになっているためである.)
とあります.
newLispはschemeぽいですが、実装はこの点に関してはここでいうcommon language的.