您已经在Lisp中实现了递归函数。
这将允许匿名递归函数。
此外,递归函数也增强了语言的表达能力。
In addition, recursive functions add significant expressive power to the language.
让我们来看一些基于链表的递归函数示例。
Let's look at a few examples of recursive functions on linked lists.
得到的样式表有太多递归函数,难以调试。
The resulting stylesheets have many recursive functions and are difficult to debug.
但是只用递归函数来遍历树并不十分困难。
But walking a tree just by using recursive functions is not all that difficult.
答案是递归函数。
实际上,可以认为循环和递归函数是能够相互转换的。
In fact, loops and recursive functions can be considered interchangeable.
您可以开发递归函数来处理项、项中的对象、作者等等。
You can develop recursive functions to handle entries, objects within entries, authors, and so on.
了解为什么需要堆栈的最好方法是查看递归函数的情况。
The best way to see why stacks are needed is to look at recursive functions. For simplicity, let's look at the recursive implementation of the factorial function.
这对于所有的函数来说都是这样,而不仅仅是递归函数如此。
不过,对于递归函数的使用,人们所关心的一个问题是栈空间的增长。
However, one concern people have with the use of recursive functions is the growth of stack space.
这就是递归函数是如何保证其他活动函数调用中的变量值不受影响的。
This is how recursive functions keep from trashing the values of the variables in other, active function calls.
可能理解它的最佳途径是接触一个实际的例子,我们需要一个递归函数。
Probably the best way to understand is with a real example and to do that, we need a recursive function.
当我们将循环转化为递归函数时,递归调用是函数所做的最后一件事情。
When we converted our loop to a recursive function, the recursive call was the last thing that the function did.
在表1中了解循环的特性,看它们可以如何与递归函数的特性相对比。
Take a look at the properties of loops and see how they compare with those of recursive functions in Table 1.
让我们来研究一个打印报表的常见循环,了解如何将它转化为一个递归函数。
Let's take a look at a common loop for printing reports and see how it can convert into a recursive function.
编写这种递归函数需要执行的步骤如下所示,清单3给出了这个函数的源代码。
The steps required to write such a recursive function are listed below, and Listing 3 presents the source code of the function itself.
递归函数有时对资源的消耗量很大,而且在用户失去耐心之前可能还没有返回结果。
Recursive functions can sometimes be very resource hungry and may not return results before a user loses patience.
在编写递归函数时,命名let能够相当程度地减少键盘输入以及出现错误的数量。
The named let cuts down considerably on the amount of typing and mistakes made when writing recursive functions.
而在Erlang中不需要使用循环,因为尾递归函数会被自动优化在固定的空间中运行。
In Erlang there is no need for loops because tail recursive functions are transparently optimized to run in constant space.
语言规范可能支持goto语句和递归函数调用,但使用其他方法能够让代码更易于理解。
Goto statements and recursive function calls may be supported by the language definition, but it is known that using other methods makes the code easier to understand.
稍后还会看到(在编写函数中)这些函数如何构成了Haskell中众多递归函数的基础。
You'll see later (in Writing functions) how these functions form the backbone of many recursive functions in Haskell.
获得新版本后,我们将调用这个find()方法,替代前面介绍的递归函数,您也应该如此。
We will be substituting a call to this find() method for our recursive function described previously when we get this new version, and so should you.
记住当程序进行函数调用(特别是针对递归函数)时,它必须在堆栈上存储返回地址和本地变量。
Remember that when a program makes a function call (especially for recursive ones), it has to store its return address and local variables on the stack.
区别在于,使用递归函数极少被迫修改任何一个变量——只需要将新值作为参数传递给下一次函数调用。
The difference is that with recursive functions, you rarely have to modify any variable — you just pass the new values as parameters to the next function call.
如果我们能找到一个除去这些不需要的栈结构的方法,那么我们的尾部递归函数就可以在固定大小的栈中运行。
If we could find a way to remove these unneeded stack frames, our tail-recursive functions would run in a constant stack size.
请注意在SPE上编写深度递归函数有些问题,原因是在SPE上没有任何堆栈溢出保护,而且本地存储也很小。
Just note that writing deeply recursive functions on the SPE is problematic because there is no stack overflow protection on the SPE, and the local store is small to begin with.
第 5章介绍了划分问题、递归函数到迭代函数的转换(我可以向您保证,这非常有趣)以及阶乘和斐波纳级数的实现。
Chapter 5 deals with partitioning problems, converting recursive functions to iterative functions (it's fun, I assure you), and more factorial and Fibonacci series implementations.
这个递归函数能很好地工作,不过它有一个主要的缺点 ——递归的每一次迭代都要为the-string传递相同的值。
This recursive function works fine, but it has one main shortcoming -- every iteration of the recursion will be passing the same value for the-string.
应用推荐