tailieunhanh - An Introduction to Programming in Emacs Lisp phần 6

Đánh giá chức năng hình tam giác-đệ quy. Số 2 là thông qua chức năng hình tam giác-đệ quy. Chúng tôi biết điều gì sẽ xảy ra khi Emacs đánh giá trianglerecursively với một đối số 2. Sau khi trải qua chuỗi các hành động được mô tả trước đó, nó trả về một giá trị của 3. | Recursion Example Using cond 139 Step 3 Evaluate the triangle-recursively function. The number 2 is passed to the triangle-recursively function. We know what happens when Emacs evaluates triangle-recursively with an argument of 2. After going through the sequence of actions described earlier it returns a value of 3. So that is what will happen here. Step 4 Evaluate the addition. 3 will be passed as an argument to the addition and will be added to the number with which the function was called which is 3. The value returned by the function as a whole will be 6. Now that we know what will happen when triangle-recursively is called with an argument of 3 it is evident what will happen if it is called with an argument of 4 In the recursive call the evaluation of triangle-recursively 1- 4 will return the value of evaluating triangle-recursively 3 which is 6 and this value will be added to 4 by the addition in the third line. The value returned by the function as a whole will be 10. Each time triangle-recursively is evaluated it evaluates a version of itself a different instance of itself with a smaller argument until the argument is small enough so that it does not evaluate itself. Note that this particular design for a recursive function requires that operations be deferred. Before triangle-recursively 7 can calculate its answer it must call triangle-recursively 6 and before triangle-recursively 6 can calculate its answer it must call triangle-recursively 5 and so on. That is to say the calculation that triangle-recursively 7 makes must be deferred until triangle-recursively 6 makes its calculation and triangle-recursively 6 must defer until triangle-recursively 5 completes and so on. If each of these instances of triangle-recursively are thought of as different robots the first robot must wait for the second to complete its job which must wait until the third completes and so on. There is a way around this kind of waiting which we will discuss in Section .

TỪ KHÓA LIÊN QUAN