sicp-4-3-3
4.51 It would always be (a b 1). 4.52 (define (analyze-if-fail exp) (let ((first (analyze (cadr exp))) (second (analyze (caddr exp)))) (lambda (env succeed fail) (first env (lambda (value fail2) (succeed value fail2)) (lambda () (second env succeed fail)))))) 4.53 (let ((pairs '())) (if-fail (let ((p (prime-sum-pair '(1 3 5...
sicp-4-3-2
4.39 (require (> miller cooper)) (require (not (= baker 5))) (require (not (= cooper 1))) (require (not (= fletcher 5))) (require (not (= fletcher 1))) (require (not (= (abs (- smith fletcher)) 1))) (require (distinct? (list baker cooper fletcher miller smith)))(require (not (= (abs (- fletcher cooper)) 1))) The answer...
sicp-4-3-1
I just find 4.3 very hard to understand. Eventhough I followed the author’s ideas, and find it work. But this time I found even try to understand the callings through debug would be very difficult. There should be theoretical foundations for this, finally, though this tutorial, I found the idea...
sicp-4-2-3
4.32 In the current version, car is lazy as well, which makes it possible to build structures such as infinite tree. 4.33 ;'(a b c)-->(cons 'a (cons 'b (cons 'c '()))) ((quoted? exp) (text-of-quotation exp env)) (define (list->cons lst) (if (null? lst) '() (list 'cons (list 'quote (car lst)) (list->cons...
sicp-4-2-1
4.25 (define (unless condition usual-value exceptional-value) (if condition exceptional-value usual-value)) (define (factorial n) (unless (= n 1) (* n (factorial (- n 1))) 1)) In applicative-order, factorial will enter an infinite loop, as the exceptional-value is evaluated regardless the condition. While in normal-order, the condition is judged before exceptional-value is...
sicp-4-1-6-4-1-7
4.16 a: (define (lookup-variable-value var env) (define (env-loop env) (define (scan vars vals) (cond ((null? vars) (env-loop (enclosing-environment env))) ((eq? var (car vars)) (if (equal? (car vals) '*unassigned*) (error "Unassigned variable" var) (car vals))) (else (scan (cdr vars) (cdr vals))))) (if (eq? env the-empty-environment) (error "Unbound variable" var) (let ((frame...
sicp-4-1-3-4-1-5
4.11 (define (make-frame variables values) (if (= (length variables) (length values)) (map cons variables values) (error "length mismatch -- MAKE-FRAME" variables values))) (define (frame-variables frame) (map car frame)) (define (frame-values frame) (map cdr frame)) 4.12 I can only come up with a find-binding-frame function and manually controls its process under...
sicp-4-1
4.1 It takes me several minutes to really understand the quanstion. :( It really only has something to do with the order of the parameter evaluation. To restrict the order, the parameters passed in to cons should be taken out explicitly before being used. (define (list-of-values-left-right exps env) (if (no-operands...
sicp-3-5-4-3-5-5
3.77 (define (integral delayed-integrand initial-value dt) (cons-stream initial-value (let ((integrand (force delayed-integrand))) (if (stream-null? integrand) the-empty-stream (integral (delay (stream-cdr integrand)) (+ (* dt (stream-car integrand)) initial-value) dt))))) 3.78 (define (integral delayed-integrand initial-value dt) (cons-stream initial-value (let ((integrand (force delayed-integrand))) (if (stream-null? integrand) the-empty-stream (integral (delay (stream-cdr integrand)) (+ (* dt...
sicp-3-5-3
3.63 guess is used to share the computation result between the succssive calling. Otherwise each call to sqrt-stream x would require recursively calling. If memo-proc is not used, these two versions would be the same efficiency. 3.64 (define (stream-limit s tolerance) (let ((s2 (stream-cdr s))) (if (< (abs (- (stream-car...
sicp-3-5-1-3-5-2
Code from the text. (define (stream-ref s n) (if (= n 0) (stream-car s) (stream-ref (stream-cdr s) (- n 1)))) (define (stream-map proc s) (if (stream-null? s) the-empty-stream (cons-stream (proc (stream-car s)) (stream-map proc (stream-cdr s))))) (define (stream-for-each proc s) (if (stream-null? s) 'done (begin (proc (stream-car s)) (stream-for-each proc...
sicp-3-4
3.39 101: P1 , P2 121: P2, P1 100: P1 computes (* x x), then P2 completes and sets x to 101, then P1 executes the assignment. 3.41 As withdraw and diposit are both single modification operations, it is not necessary to protect the balance value, as it would always...
sicp-3-3-5
3.33 (define (average a b c) (let ((x (make-connector)) (y (make-connector))) (adder a b x) (multiplier c v u) (constant 2 v)) 'ok) 3.34 it is only one-directianl computation. Given the value of b, the value of a can not be evaluated, as the multiplier does not know the left...