|improver? I hardly KNOW 'er!
||[Jul. 9th, 2008|03:43 pm]
Today and yesterday have been amazing for SICP checkins. I've finished 17 problems in the last 48 hours! Here's my answer to the last problem in chapter 1:
;; ...Write a procedure /iterative-improve/ that takes two procedures as
;; arguments: a method for telling whether a guess is good enough and a method
;; for improving a guess. /Iterative-improve/ should return as its value a
;; procedure that takes a guess as argument and keeps improving the guess
;; until it is good enough. Rewrite the /sqrt/ procedure of section 1.1.7 and
;; the /fixed-point/ procedure of section 1.3.3 in terms of
(lambda (good-enough? improve)
(letrec ((improver (lambda (guess)
(if (good-enough? guess)
(improver (improve guess))))))
(define (improve guess)
(average guess (/ x guess)))
(define (good-enough? guess)
(< (abs (- (square guess) x)) 0.001))
((iterative-improve good-enough? improve) 1.0)))
(lambda (f first-guess)
(define (next guess)
(define (close-enough? guess)
(< (abs (- guess (next guess))) tolerance))
((iterative-improve close-enough? next) first-guess)))
I just love writing stuff that looks like this, especially
iterative-improve. Why write code that does something when you can write code that does anything? Whee!
There's just one problem left to finish -- the second half of this one. It's sticky, but I think I can get it done before the start of ICFP. You know, even if the contest is a wash, I'll feel good going into it knowing I can do all the exercises in the first chapter of this book. I feel so much stronger than I did four months ago.
oh, shit, i never finished the perturbation thing. hmmm.
you might like Haskell, then (or anything in the ML family). Instead of using "map" to map over lists, you can use "fmap" for any kind of data that implements the Functor interface. instead of "foldl" to reduce lists, you can use "foldl'
" to reduce anything that implements the Foldable interface.
conversely! I've been reading about Defunctionalization
: the refactoring method of taking the magic out to see what's really going on
someone on the pdxfunc mailing list called last year's ICFP "very
hard, probably the most difficult one ever."
I intend to kick their ass, programmatically.
I know, I know. A few months ago, Sam
told me, "You need
to learn Haskell." There aren't that many things that Sam Rebelsky tells me I need
to do, y'know? And Paul says, "Lindsey, I tell everyone to learn Haskell, but in your case, I really mean
It really is on my list. I intend to take a break from Scheme after the contest is over. I feel like the end of chapter 1 is a good stopping point for now. I want to keep going with it, but there's just so much other stuff to learn.
this is pretty awesome. you've inspired me to do the same thing.