March 26th Monday (三月 二十六日 月曜日)
来源:互联网 发布:网络交换器什么牌子好 编辑:程序博客网 时间:2024/04/19 21:49
(define (f x) (cons 'x x))
(define (zero f)
(lambda (x)
x))
(define (one f)
(lambda (x)
(f x)))
(define (two f)
(lambda (x)
(f (f x))))
(define (three f)
(lambda (x)
(f (f (f x)))))
(define (add-one n)
(lambda (f)
(lambda (x)
(f ((n f) x)))))
(define (add a b)
(lambda (f)
(lambda (x)
((a f) ((b f) x)))))
(define (mul a b)
(lambda (f) (lambda (x) ((a (b f)) x))))
The above list are all Church Numbers. Yes, it is so famous. At the begin of learning them, I
was confused. Having gong over the comprehension I found it is so simple. I thought I know how
to Church invent those interesting numbers. In fact, he just found it.
Let's look at "one", "two", "three", and "zero". As a matter of fact, those numbers all are
high order operators. That is to say, they like "map", "for-each", they take a function and one
parameter. What is the discrepancy between "map" and them? Look inside of them!
The "zero" is just return its argument and not call the function taken; the "one" just call its
function to its argument taken one time; the "two" call the function to its argument only two
times. From them, we know a new way to counter -- composing a function with a parameter.
((two f) 'z) => (x x . 'z)
So, the "add-one" is also simple. Firstly, let's look at the above statement how to use "two".
The "(two f)" is the key to understand "add-one", "add". The "((n f) x)" is alike the "((two f) 'z)".
Yes, it will compose "f" with "x". Finally, compose "f" again. In other words, call "f" with a result
returned from "((n f) x)". Now the "add" is easy to understand! Having composing "f" "b" times with "x",
call the result function from "(a f)" with result returned from "((b f) x)".
Now we know it is so important for Church numbers or related operators to make a correct composite
function. So, the "mul" is also not hard to understand. The "(two f)" will make a composite function
like "(f (f (f ...)))". The "(a (b f))" is mean to compose "f" "(a - 1) * (b - 1)" times. For example,
if "a" is three and "b" is two, the number of composing "f" is (3-1) * (2-1) = 2. "(f (f ...))" resulted
from "(two f)", "(p (p (p ...)" resulted from "(three p)". Having substituted "(f (f ...))" for "p". The
final composite result is "(f (f (f (f (f (f ...))))))". OK, our goal reached at.
- March 26th Monday (三月 二十六日 月曜日)
- 2009 March 16th Monday (三月 十六日 月曜日)
- 2008 March 26th Wednesday (三月 二十六日 水曜日)
- 2009 March 26th Thursday (三月 二十六日 木曜日)
- 2009 March 23th Monday (三月 二十三日 月曜日)
- March 12th Monday (三月 十二日 月曜日)
- March 19th Monday (三月 十九日 月曜日)
- Februray 26th Monday (一月 二十六日 月曜日)
- 2008 May 26th Monday (五月 二十六日 月曜日)
- 2008 March 24th Monday (三月 二十四日 月曜日)
- March 16th Friday (三月 十六日 金曜日)
- March 5th Monday (三月 五日 月曜日)
- 2008 March 10th Monday (三月 十日 月曜日)
- 2008 March 17th Monday (三月 十七日 月曜日)
- 2008 March 31th Monday (三月 三十一日 月曜日)
- 2009 March 9th Monday (三月 九日 月曜日)
- 2009 March 30th Monday (三月 三十日 月曜日)
- 2009 March 2nd Monday (三月 二日 月曜日)
- March 20th Tuesday (三月 二十日 火曜日)
- March 21th Wednesday (三月 二十一日 水曜日)
- 项目团队管理问题
- March 22th Thursday (三月 二十二日 木曜日)
- March 23th Friday (三月 二十三日 金曜日)
- March 26th Monday (三月 二十六日 月曜日)
- tomcat配置技巧
- IT项目管理经验分享
- sql2000挂起无法安装的问题
- 图像编程的若干常用操作(旋转,透明等)
- 构建自己的操作系统[2]-Loader
- tomcat下中文乱码的解决
- 如何在Windows2000中动态禁用/启用Ctrl-Alt-Delete
- Oracle 行列转置