SICP使用DRscheme遇到的问题

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))

这边使用 Drscheme时,会出错,显示没有runtime过程。

解决方法是 选择语言 PLT-MZscheme 然后将程序改为下面的:
(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)


那么这道题就是这么写了:
(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)

你可能感兴趣的:(F#)