sicp吧 关注:46贴子:83
  • 8回复贴,共1

Exercise 2.6, Church numerals 丘奇计数。附测试代码

只看楼主收藏回复

- -弄明白的时候 很爽很爽
运行环境 DrRacket

#lang planet neil/sicp
(define zero
(lambda (f) (lambda (x) x)))
(define (add-1 n)
(lambda (f) (lambda (x) (f ((n f) x)))))
(define one
(lambda (f) (lambda (x) (f x))))
(define two
(lambda (f) (lambda (x) (f (f x)))))
(define (add m n)
(lambda (f)
(lambda (x)
((m f) ((n f) x)))))
; 怎么检验啊= =
; 啊!“对0应用n次后继函数”=n ~
(define (to-num n)
(define (suc x) (+ 1 x))
((n suc) 0))
(to-num zero)
(to-num one)
(to-num two)
(to-num (add-1 two))
(to-num (add two two))


IP属地:上海1楼2016-01-20 21:59回复
    求楼主解释。。。一直弄不明白


    IP属地:浙江来自Android客户端2楼2016-11-20 20:13
    收起回复