正在加载图片...
6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Slide 5.1.4 Procedural abstraction We need to provide it with inputs of a specified type Process of procedural abstraction Hide mentation detalls from user, who just invokes name to apply procedure Input: type DOt sIcP Slide 5. 1.5 Procedural a We know by the contract associated with the procedure that if Process of procedural abstraction we provide inputs of the appropriate type, the procedure will produce an output of a specified type Hide implementation details from user, who just invokes name to 6001 ICP Procedural abstraction Slide 5.1.6 Define formal parameters, capture process in body of procedure 6 and by giving the whole procedure a name, we create this Process of pro lack box abstraction, in which we can use the procedure Give proclementation detalls from user, who just Invokes name to without knowing details. This means that the procedure will Hide obey the contract that specifies the mapping from inputs to outputs, but the user is not aware of the details by which that contract is enforced etails of contract for Output: type erting input to output Slide 5.1.7 Procedural abstraction example: sqrt So let's use this idea to look at a more interesting algorithm than To find an approximation of square root of x the earlier ones we' ve examined. Here, again, is Heron of Make a guess G Alexandria's algorithm for computing good approximations to Keep improving the guess until it is good enough the square root of a positive number. Read the steps carefully, as 6001 SICP6.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 5.1.4 We need to provide it with inputs of a specified type. Slide 5.1.5 We know by the contract associated with the procedure, that if we provide inputs of the appropriate type, the procedure will produce an output of a specified type... Slide 5.1.6 ... and by giving the whole procedure a name, we create this black box abstraction, in which we can use the procedure without knowing details. This means that the procedure will obey the contract that specifies the mapping from inputs to outputs, but the user is not aware of the details by which that contract is enforced. Slide 5.1.7 So let's use this idea to look at a more interesting algorithm than the earlier ones we've examined. Here, again, is Heron of Alexandria's algorithm for computing good approximations to the square root of a positive number. Read the steps carefully, as we are about to implement them
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有