SICP使用DRscheme遇到的问题

[code]
SICP Exercise 1.22

(define (timed-prime-test n)
(newline)
(display n)
(start-prime-test n (runtime)))

(define (start-prime-test n start-time)
(if (prime? n)
(report-prime (- (runtime) start-time))))

(define (report-prime elapsed-time)
(display " *** ")
(display elapsed-time))[/code]
这边使用 Drscheme时,会出错,显示没有runtime过程。

解决方法是 选择语言 PLT-MZscheme 然后将程序改为下面的:
[code](define (timed-prime-test n)
(newline)
(display n)
(start-prime-test n (current-milliseconds)))

(define (start-prime-test n start-time)
(if (prime? n)
(report-prime (- (current-milliseconds) start-time))))

(define (report-prime elapsed-time)
(display " *** ")
(display elapsed-time)
(display " ms "))
(timed-prime-test 100000000057)[/code]

那么这道题就是这么写了:
[code]
(define (f start count)
(cond ((= 0 count)
(newline)
(display "***** FINISHED *****")
(newline))
((timed-prime-test start) (f (+ 2 start) (- count 1)))
(else (f (+ 2 start) count))))
(define (search-for-primes a)
(f (+ a 1) 3))
(search-for-primes 1000)[/code]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值