I got the "schema application not procedure" in the last recursive function call

so here is the code:

(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 nm) (if (< nm) ((time-prime-test n) (search-for-primes (+ n 1) m)) (display " calculating stopped. "))) (search-for-primes 100000 100020) 

and I got this error after "calculation stopped" .. as shown below:

100017 100018 100019 * 54 calculation stopped., Application: not a procedure; expected procedure that can be applied to arguments
given: # <void>
arguments ...:
# & L; void>

+7
source share
2 answers

You intend to execute two expressions inside the next part of if , but if allows only one expression in the following and one in the alternative.

Rounding both expressions between brackets (like you) will not work: the resulting expression will be evaluated as a function application of the first expression with the second expression as its argument, creating an error "application: not a procedure; expected a procedure that can be applied to arguments ..." because (time-prime-test n) does not evaluate the procedure, it evaluates #<void> .

You can fix this problem either with cond :

 (define (search-for-primes nm) (cond ((< nm) (time-prime-test n) (search-for-primes (+ n 1) m)) (else (display " calculating stopped. ")))) 

Or a begin :

 (define (search-for-primes nm) (if (< nm) (begin (time-prime-test n) (search-for-primes (+ n 1) m)) (display " calculating stopped. "))) 
+16
source
  ((time-prime-test n) (search-for-primes (+ n 1) m)) 

This will try to apply the result of time-prime-test as a procedure. time-prime-test does not return a procedure. Use begin :

  (begin (time-prime-test n) (search-for-primes (+ n 1) m)) 
+3
source

All Articles