正在加载图片...
6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Slide 6.2. 13 The same reasoning helps us deduce the form for the third Lets check this new procedure out! parameter(a procedure mapping numbers to numbers) for the (define (sum term a nex b) fourth parameter(a number) (+(term a) (sum term (next a) next b)))) What is the type of this procedure? aber] number, number umber?number number)?number Slide 6.2.14 Let's check this new procedure out and overall this procedure, sum, will return a number, since (define (sum term a nex b) both clauses of the if expression that forms the body of the (Ir(e a b) procedure must return a number (+(term a) Thus we can characterize the type of this new procedure, sum. It (sum term(next a) next b))) just happens that some of the parameters for this procedure are What is the type of this procedure? themselves proced ures number number→ number 6001 SICP Slide 6.2.15 o this is a new kind of beast, which we call a higher order Higher order procedures procedure. It is a procedure that takes as inputs other procedures,I. A higher order procedur and it may, as we will see, also return a procedure as its returned takes a procedure as an argument or returns one as a value tsun (lambda (x) x) a(lambda (x) ( x 1))b) square, or they may be pure lambda expressions. In either o Note that those input procedures may be named procedures, like (define (sun-squares1 a b) a(1 anda《x)什x1))b)) (define (pi- case, we know that the value of the expression will be a procedure oda lambda object that can then be substituted into the body of sum And now we see that we have captured the common pattern of summation, and that our three earlier expressions are just special versions of this general computation 1 001 SICP Does this really work? Well, just use the substitution model to check that procedures get substituted in the right places in the body of sum and that as a consequence the three expressions shown here will compute the appropriate series of terms 6.001 Notes: Section 6.36.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 6.2.13 The same reasoning helps us deduce the form for the third parameter (a procedure mapping numbers to numbers) for the fourth parameter (a number). Slide 6.2.14 ... and overall this procedure, sum, will return a number, since both clauses of the if expression that forms the body of the procedure must return a number. Thus we can characterize the type of this new procedure, sum. It just happens that some of the parameters for this procedure are themselves procedures! Slide 6.2.15 So this is a new kind of beast, which we call a higher order procedure. It is a procedure that takes as inputs other procedures, and it may, as we will see, also return a procedure as its returned value. Note that those input procedures may be named procedures, like square, or they may be pure lambda expressions. In either case, we know that the value of the expression will be a procedure object that can then be substituted into the body of sum. And now we see that we have captured the common pattern of summation, and that our three earlier expressions are just special versions of this general computation. Does this really work? Well, just use the substitution model to check that procedures get substituted in the right places in the body of sum and that as a consequence the three expressions shown here will compute the appropriate series of terms. 6.001 Notes: Section 6.3
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有