> <\body> <\hide-preamble> >>> <\slideshow> <\slide> \; \; \; \; \<#57FA\>\<#7840\>SICP 07>|>>|\<#6D6A\>\<#718A\>\<#732B\>\<#513F\>>>>|>>|\<#9AD8\>\<#9636\>\<#51FD\>\<#6570\>\<#505A\>\<#62BD\>\<#8C61\>>> <\slide> \<#57FA\>\<#7840\>SICP\<#FF1A\>\<#7B2C\>7\<#8BFE\>> <\wide-tabular> || \<#7528\>\<#9AD8\>\<#9636\>\<#51FD\>\<#6570\>\<#505A\>\<#62BD\>\<#8C61\> > |<\cell> <\very-large> >| \<#5728\>\<#53C2\>\<#6570\>\<#4E2D\>\<#4F20\>\<#9012\>\<#51FD\>\<#6570\>\<#503C\> |<\cell> Procedures as Arguments >| \<#7528\>\<#6784\>\<#9020\>\<#533F\>\<#540D\>\<#51FD\>\<#6570\> |<\cell> Constructing Procedures Using >| \<#51FD\>\<#6570\>\<#4F5C\>\<#4E3A\>\<#4E00\>\<#822C\>\<#6027\>\<#7684\>\<#65B9\>\<#6CD5\> |<\cell> Procedures as General Methods >| \<#5728\>\<#51FD\>\<#6570\>\<#4E2D\>\<#8FD4\>\<#56DE\>\<#51FD\>\<#6570\>\<#503C\> |<\cell> Procedures as Returned Values >>> \; \<#7A0B\>\<#7684\>\<#57FA\>\<#672C\>\<#539F\>\<#7406\>\<#662F\>\<#5BF9\>\<#6570\>\<#636E\>\<#548C\>\<#8BA1\>\<#7B97\>\<#7684\>\<#7EC4\>\<#5408\>\<#548C\>\<#62BD\>\<#8C61\>> <\slide> \<#53C2\>\<#6570\>\<#4E2D\>\<#4F20\>\<#9012\>\<#51FD\>\<#6570\>\<#503C\>> <\with|par-columns|2> <\equation*> f=f+\+f <\equation*> i=1+2+\+100=5050 <\equation*> lim+\>>=|8> <\session|scheme|default> <\folded-io|Scheme] > (define (sum f a next b) \ \ (if (\ a b) \ \ \ \ \ \ 0 \ \ \ \ \ \ (+ (f a) \ \ \ \ \ \ \ \ \ (sum f (next a) next b)))) <|folded-io> sum <\folded-io|Scheme] > (define (inc n) (+ n 1)) <|folded-io> inc <\folded-io|Scheme] > (define (same x) x) <|folded-io> same <\folded-io|Scheme] > \; <|folded-io> 5050 <\session|scheme|default> <\unfolded-io|Scheme] > (sum 1 100) <|unfolded-io> 5050 <\input|Scheme] > \; \; <\slide> \<#6784\>\<#9020\>\<#533F\>\<#540D\>\<#51FD\>\<#6570\>> <\equation*> i=1+2+\+10 \; <\session|scheme|default> <\folded-io|Scheme] > (sum (lambda (x) (* x x)) 1 10) <|folded-io> 385 <\input|Scheme] > \; \; <\equation*> 1+3+5+7+9 <\session|scheme|default> <\folded-io|Scheme] > (sum (lambda (x) (* x x)) 1 (lambda (x) (+ x 2)) 10) <|folded-io> 165 <\unfolded-io|Scheme] > (sum (lambda (x) (* x x)) 2 (lambda (x) (+ x 2)) 10) <|unfolded-io> 220 <\input|Scheme] > \; <\slide> \<#521B\>\<#5EFA\>\<#5C40\>\<#90E8\>\<#53D8\>\<#91CF\>> <\session|scheme|default> <\unfolded-io|Scheme] > (define (fib-once pair) \ \ (let ((a (first pair)) \ \ \ \ \ \ \ \ (b (second pair))) \ \ \ (list b (+ a b)))) <|unfolded-io> fib-once <\unfolded-io|Scheme] > (fib-once (fib-once (list 1 1))) <|unfolded-io> (2 3) <\input|Scheme] > \; \; <\slide> \<#4F8B\>\<#5206\>\<#6790\>\<#FF1A\>\<#533A\>\<#95F4\>\<#6298\>\<#534A\>\<#6CD5\>> <\gr-screen> |gr-frame|>|gr-geometry||gr-grid||1>|gr-grid-old||1>|gr-edit-grid-aspect|||>|gr-edit-grid||1>|gr-edit-grid-old||1>|gr-color|magenta|||||>|||>>||||>|>||>|||>|||>||>>||>>||>>||>>>> <\slide> \<#73B0\>\<#FF1A\>\<#4E8C\>\<#5206\>\<#67E5\>\<#627E\>\<#6CD5\>> <\session|scheme|default> <\unfolded-io|Scheme] > (define (average x y) (/ (+ x y) 2)) <|unfolded-io> average <\unfolded-io|Scheme] > (define (search f neg-point pos-point) \ \ (let ((midpoint (average neg-point pos-point))) \ \ \ \ (if (close-enough? neg-point pos-point) \ \ \ \ \ \ \ \ midpoint \ \ \ \ \ \ \ \ (let ((test-value (f midpoint))) \ \ \ \ \ \ \ \ \ \ (cond ((positive? test-value) \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (search f neg-point midpoint)) \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ((negative? test-value) \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (search f midpoint pos-point)) \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (else midpoint)))))) <|unfolded-io> search <\slide> \<#73B0\>\<#FF1A\>\<#533A\>\<#95F4\>\<#6298\>\<#534A\>\<#6CD5\>> <\session|scheme|default> <\folded-io|Scheme] > (define (close-enough? x y) \ \ (\ (abs (- x y)) 0.001)) <|folded-io> close-enough? <\folded-io|Scheme] > (define (half-interval-method f a b) \ \ (let ((a-value (f a)) \ \ \ \ \ \ \ \ (b-value (f b))) \ \ \ \ (cond ((and (negative? a-value) (positive? b-value)) \ \ \ \ \ \ \ \ \ \ \ (search f a b)) \ \ \ \ \ \ \ \ \ \ ((and (negative? b-value) (positive? a-value)) \ \ \ \ \ \ \ \ \ \ \ (search f b a)) \ \ \ \ \ \ \ \ \ \ (else \ \ \ \ \ \ \ \ \ \ \ (error "Values are not of opposite sign" a b))))) <|folded-io> half-interval-method <\unfolded-io|Scheme] > (half-interval-method sin 2.0 4.0) <|unfolded-io> 3.14111328125 <\slide> \<#4F8B\>\<#5206\>\<#6790\>\<#FF1A\>\<#5BFB\>\<#627E\>\<#4E0D\>\<#52A8\>\<#70B9\>> <\equation*> f,f|)>,f|)>|)>,\ <\session|scheme|default> <\folded-io|Scheme] > (define tolerance 0.00001) <|folded-io> 0.00001 <\folded-io|Scheme] > (define (fixed-point f first-guess) \ \ (define (close-enough? v1 v2) \ \ \ \ (\ (abs (- v1 v2)) tolerance)) \ \ (define (try guess) \ \ \ \ (let ((next (f guess))) \ \ \ \ \ \ (if (close-enough? guess next) \ \ \ \ \ \ \ \ \ \ next \ \ \ \ \ \ \ \ \ \ (try next)))) \ \ (try first-guess)) <|folded-io> fixed-point <\folded-io|Scheme] > (fixed-point cos 1.0) <|folded-io> 0.7390822985224024 <\folded-io|Scheme] > (fixed-point (lambda (y) (+ (sin y) (cos y))) 1.0) <|folded-io> 1.2587315962971173 <\slide> \<#7ED3\>> \<#4EE3\>\<#7801\>\<#5373\>\<#6570\>\<#636E\>\<#FF0C\>\<#6570\>\<#636E\>\<#5373\>\<#4EE3\>\<#7801\>\<#3002\> \<#51FD\>\<#6570\>\<#503C\>\<#53EF\>\<#4EE5\>\<#50CF\>\<#6570\>\<#636E\>\<#4E00\>\<#6837\>\<#FF0C\>\<#4F5C\>\<#4E3A\>\<#53C2\>\<#6570\>\<#4F20\>\<#5165\>\<#51FD\>\<#6570\>\<#FF0C\>\<#4F5C\>\<#4E3A\>\<#8FD4\>\<#56DE\>\<#503C\>\<#4ECE\>\<#51FD\>\<#6570\>\<#4E2D\>\<#4F20\>\<#51FA\>\<#3002\> \<#FF0C\>\<#FF0C\> <\scm-code> (define (\<#51FD\>\<#6570\>\<#540D\>\ >\<#5F62\>\<#5F0F\>\<#53C2\>\<#6570\>\<#5217\>\<#8868\>\>) \<#4E3B\>\<#4F53\>\>) (lambda (\<#5F62\>\<#5F0F\>\<#53C2\>\<#6570\>\<#5217\>\<#8868\>\>) \<#4E3B\>\<#4F53\>\>) \; (let ((\<#53D8\>\<#91CF\>1\> \<#8868\>\<#8FBE\>\<#5F0F\>1\>) \ \ \ \ \ \ (\<#53D8\>\<#91CF\>2\> \<#8868\>\<#8FBE\>\<#5F0F\>2\>) \ \ \ \ \ \ ... \ \ \ \ \ \ (\<#53D8\>\<#91CF\>n\> \<#8868\>\<#8FBE\>\<#5F0F\>n\>)) \ \ \ \<#4E3B\>\<#4F53\>\>) <\initial> <\collection>