One subsection of 1.3 remains.
But before hitting that, I have to say I am impressed with scheme.
Procedures that return dynamically generated procedures!? That's just awesome. I've heard that MIT actually took scheme off the curriculum last year, which is a real pity. There's no doubt this stuff is difficult. Mapping out in my head how I'm going to put down an iterative process where each step depends on the previous step is interesting. The moment of realizing the solution is awesome.
In this particular case I'm referring to the iterative solution of 1.37: it involves implementing a function to calculate the k-term finite continued fraction and can be found here: http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-12.html#%_sec_1.3
My solution:
N and D are procedures that should return the nth operands.
start at the end(where we have Nk/Dk), work backwards.
(define (cont-frac-iter n d k)
(define (iter a result)
(if (< a 0)
result
(iter (- a 1) (/(n a) (+ (d a) result)))))
(iter k 0))
I don't think I'd use it for actual projects unless there are some far better tools and libraries out there. But while I was pretty confident in my programming abilities, this is making me think of all kind of fresh things. Awesome book.
No comments:
Post a Comment