所以这是代码:
(define (time-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))
(define (search-for-primes n m)
(if (< n m)
((time-prime-test n)
(search-for-primes (+ n 1) m))
(display " calculating stopped. ")))
(search-for-primes 100000 100020)
我在“计算停止”后收到此错误。已显示。像下面这样:
100017
100018
100019*54 计算停止。 。 。应用程序:不是一个程序;期望有一个可以应用于参数的过程
给定:#
论据...:
#
您打算在后续部分中执行两个表达式if
, but if
只允许在结果中使用一种表达方式,在替代中使用一种表达方式。
将两个表达式放在括号之间(就像您所做的那样)将不起作用:结果表达式将被评估为第一个表达式的函数应用程序,第二个表达式作为其参数,从而产生错误"application: not a procedure; expected a procedure that can be applied to arguments ..."
, 因为(time-prime-test n)
不评估一个过程,它评估#<void>
.
您可以通过使用cond
:
(define (search-for-primes n m)
(cond ((< n m)
(time-prime-test n)
(search-for-primes (+ n 1) m))
(else
(display " calculating stopped. "))))
Or a begin
:
(define (search-for-primes n m)
(if (< n m)
(begin
(time-prime-test n)
(search-for-primes (+ n 1) m))
(display " calculating stopped. ")))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)