sicp-4-3-3
Posted on 2015-03-16 21:02:58 +0900 in SICP
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 8) '(20 35 110))))
(permanent-set! pairs (cons p pairs))
(amb))
pairs))
pairs
would collect all the combinations of the two lists.
(amb)
would force iterate all the valid pairs which would be returned.
4.54
(define (analyze-require exp)
(let ((pproc (analyze (require-predicate exp))))
(lambda (env succeed fail)
(pproc env
(lambda (pred-value fail2)
(if (not (true? pre-value))
(fail2)
(succeed 'ok fail2)))
fail))))
Hide Comments
comments powered by Disqus