(define (prime? x) (define (no-factor? k lim) (cond ((>= k lim) #t) ((= (remainder x k) 0) #f) (#t (no-factor? (+ k 1) lim)))) (cond ((< x 2) #f) ((= x 2) #t) (#t (no-factor? 2 (floor (+ (sqrt x) 2)))))) (define (find? start limit body) "True iff (BODY k) yields #t for any START <= k < LIMIT." (cond ((>= start limit) #f) ((body start) #t) (#t (find? (+ start 1) limit body)))) (define (reverse L) "The reverse of list L." (define (reverse+ partial-result rest) "The reverse of REST followed by PARTIAL-RESULT" (if (null? rest) partial-result (reverse+ (cons (car rest) partial-result) (cdr rest)))) (reverse+ () L)) (define (shuffle1 L1 L2) "The list consisting of the first element of L1, then" "the first of L2, then the second of L1, etc., until" "the elements of one or the other list is exhausted." (if (null? L1) '() (cons (car L1) (shuffle1 L2 (cdr L1))))) (define (shuffle L1 L2) "The list consisting of the first element of L1, then" "the first of L2, then the second of L1, etc., until" "the elements of one or the other list is exhausted." "This version is tail-recursive." (define (shuffle+ reversed-result L1 L2) "The result of shuffling L1 and L2 and prepending the" "result to REVERSED-RESULT." (if (null? L1) (reverse reversed-result) (shuffle+ (cons (car L1) reversed-result) L2 (cdr L1)))) (shuffle+ '() L1 L2)) (define (find? start limit body) "True iff (BODY k) yields #t for any START <= k < LIMIT." (define (find-loop? k) (cond ((>= k limit) #f) ((body k) #t) (#t (find-loop? (+ k 1))))) (find-loop? start))