正在加载图片...
6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Slide 7.38 Well, we can handle that. We add another parameter to our helper procedure, which keeps track of whether to add the term define (sine x) (if the value is 1)or whether to subtract the term(if the value is 1). And of course we will need to change how we update the display )《 display n) nt is" )(display current guess, and how we update the value of this parameter 《811-enu?next) (* addit -1))))) Kaux x 10) 6 001 SICP 的4 Slide 7.3.9 Oops! We blew it somewhere! We could enter the debugger to cate the problem, but we can already guess that since we changed the aux procedure, that must be the cause sine3.1415927 , The procedure # compound-procedure 12 aux] has been called with 3 arguments: it requires Type d to debug error,o to quit back to REP loop: q 48m0 Slide 7.3.10 And clearly the solution is to make sure we call this procedure with the right number of arguments. Notice that in this case it is easy to spot this error, but in general, we should get into the current addit) habit of checking all calls to a procedure when we alter its set d8paY"ni器")( display (display curren play current) of parameters 什+ current(· addit next) auxx10-1)) 6 001 SICP Slide 7.3.1l Now, if we try this on the test case of x equal pi, this works But if we try it on the test case of pi half, it doesnt! The answer should be close to 1, but we are getting something close to-1. Note that this reinforces why we want to try a range of 5410112354a-3 test cases-if we had stopped with x equal pi, we would not is13 current is4.452067333052508e-4 have spotted this problem sue3151220 1357 1013盯41 value:-.99984310137874 6001S6.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 7.3.8 Well, we can handle that. We add another parameter to our helper procedure, which keeps track of whether to add the term (if the value is 1) or whether to subtract the term (if the value is ­ 1). And of course we will need to change how we update the guess, and how we update the value of this parameter. Slide 7.3.9 Oops! We blew it somewhere! We could enter the debugger to locate the problem, but we can already guess that since we changed the aux procedure, that must be the cause. Slide 7.3.10 And clearly the solution is to make sure we call this procedure with the right number of arguments. Notice that in this case it is easy to spot this error, but in general, we should get into the habit of checking all calls to a procedure when we alter its set of parameters. Slide 7.3.11 Now, if we try this on the test case of x equal pi, this works! But if we try it on the test case of pi half, it doesn’t! The answer should be close to 1, but we are getting something close to -1. Note that this reinforces why we want to try a range of test cases – if we had stopped with x equal pi, we would not have spotted this problem
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有