进行SICP Exercise 1.22 时遇到无法加载runtime过程的问题。
我的开发环境是DrScheme 4.2. 于是将原文的例子做了修改。修改例程和结果例程如下:
修改例程
(define (smallest-divisor n) (find-divisor n 2) ) (define (find-divisor n test-divisor) (cond ((> (square test-divisor) n) n) ((divides? test-divisor n) test-divisor) (else (find-divisor n (+ test-divisor 1))) ) ) (define (divides? a b) (= (remainder b a) 0) ) (define (prime? n) (smallest-divisor n) ) (define (square n) (* n n) ) (define (timed-prime-test n) (start-prime-test n ) ) (define (start-prime-test n ) (prime? n) )
结果例程
(define (search-for-primes n) (if (= (timed-prime-test (+ n 1)) (+ n 1)) (+ n 1) (search-for-primes (+ n 1)) ) ) (search-for-primes 100000)