some solutions for MIT Press's "structure and interpretation of computer programs", I guess
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
780 B

(define (sum term a next b)
(define (iter a result)
(if (> a b)
result
(iter (next a) (+ result (term a)))))
(iter a 0))
(define (pi-sum a b)
(sum (lambda (x) (/ 1.0 (* x (+ x 2))))
a
(lambda (x) (+ x 4))
b))
(define (integral f a b dx)
(* (sum f
(+ a (/ dx 2.0))
(lambda (x) (+ x dx))
b)
dx))
;(define (f x y)
; (define (f-helper a b)
; (+ (* x (square a))
; (* y b)
; (* a b)))
; (f-helper (+ 1 (* x y))
; (- 1 y)))
;(define (f x y)
; ((lambda (a b)
; (+ (* x (square a))
; (* y b)
; (* a b)))
; (+ 1 (* x y))
; (- 1 y)))
(define (f x y)
(let ((a (+ 1 (* x y)))
(b (- 1 y)))
(+ (* x (square a))
(* y b)
(* a b))))