sicp-4-3-1
Posted on 2015-03-13 22:47:34 +0900 in SICP
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 befind it is CPS. There are other materials here, here.
4.35
(define (an-integer-between low high)
(require (<= low high))
(amb low (an-integer-between (+ low 1) high)))
(define (a-pythagorean-triple-between low high)
(let ((i (an-integer-between low high)))
(let ((j (an-integer-between i high)))
(let ((k (an-integer-between j high)))
(require (= (+ (* i i) (* j j)) (* k k)))
(list i j k)))))
(a-pythagorean-triple-between 1 100)
4.36
(define (a-pythagorean-triple-from low)
(let ((k (an-integer-starting-from low)))
(let ((i (an-integer-between low k)))
(let ((j (an-integer-between i k)))
(require (= (+ (* i i) (* j j)) (* k k)))
(list i j k)))))
(a-pythagorean-triple-from 1)
4.37
It would cut many useless branches.
Hide Comments
comments powered by Disqus