将while/do/for/foreach-Loops转换为递归方法
Transforming while/do/for/foreach-Loops into Recursive Methods
摘要:
在软件工程中,在递归和迭代之间进行良好的选择是至关重要的,因为它们的效率和维护是不同的。事实上,开发人员经常需要将迭代转换为递归(例如,在调试中,将调用图分解为迭代);因此,非常令人惊讶的是,不存在从循环到递归的公共转换来处理所有类型的循环。本文描述了一种能够将迭代循环转换为等价递归方法的转换。这种转换是针对程序设计语言Java描述的,但它足够通用,可以适用于许多其他允许迭代和递归的语言。我们描述了将while/do/for/foreach类型的循环转换为递归所需的更改。每一种循环都需要一种特殊的处理方法,并对此进行了描述和举例说明。
英文摘要:
In software engineering, taking a good election between recursion and iteration is essential because their efficiency and maintenance are different. In fact, developers often need to transform iteration into recursion (e.g., in debugging, to decompose the call graph into iterations); thus, it is quite surprising that there does not exist a public transformation from loops to recursion that handles all kinds of loops. This article describes a transformation able to transform iterative loops into equivalent recursive methods. The transformation is described for the programming language Java, but it is general enough as to be adapted to many other languages that allow iteration and recursion. We describe the changes needed to transform loops of types while/do/for/foreach into recursion. Each kind of loop requires a particular treatment that is described and exemplified.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。