Question: Explain the Scheme code of (a) and (b). In each case explain the following components: targets of computation, data structures used, language mechanisms involved. List

Explain the Scheme code of (a) and (b). In each case explain the following components: targets of computation, data structures used, language mechanisms involved. List the main similarities and differences between (a) and (b) from the point of view of their operation.

(a) (define (filter p L) (cond ((null? L) L) ((p (car L)) (cons (car L) (filter p (cdr L)))) (else (filter p (cdr L))))) (define (not-divisible-by n) (lambda(m) (not (= 0 (remainder m n))))) (define (sieve L) (if (null? L) L (cons (car L) (sieve (filter (not-divisible-by (car L)) (cdr L)))))) (define (intlist m n) (if (> m n) '() (cons m (intlist (+ 1 m) n)))) (define (primesto n) (sieve (intlist 2 n)))

(b)

(define (filter p L) (cond ((null? L) L) ((p (car (force L))) (delay (cons (car (force L)) (filter p (cdr (force L)))))) (else (filter p (cdr (force L)))))) (define (sieve L) (delay (cons (car (force L)) (sieve (filter (not-divisible-by (car (force L))) (cdr (force L))))))) (define (intsfrom m) (delay (cons m (intsfrom (+ 1 m))))) (define primes (sieve (intsfrom 2)))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!