|
| |
| | Tail recursion - Wikipedia, the free encyclopedia |
 | | In computer science, tail recursion is a special case of recursion that can be transformed into an iteration. |  | | Note that the tail call doesn't have to literally appear after all other statements in the source code; it is only important that its result is immediately returned, since the calling function will never get a chance to do anything after the call if the optimization is performed. |  | | It is used in functional programming languages where the declarative approach and explicit handling of state emphasize recursive functions that rapidly fill the stack. |
|
http://en.wikipedia.org/wiki/Tail_recursion
(1011 words)
|
|
| |
| | ipedia.com: Recursion Article |
 | | Recursion is deeply embedded in the theory of computation, with the theoretical equivalence of recursive functions and Turing machines at the foundation of ideas about the universality of the modern computer. |  | | As a computer programming technique, this is called divide and conquer and is key to the design of many important algorithms, as well as being a fundamental part of dynamic programming. |  | | Any function that can be evaluated by a computer can be expressed in terms of recursive functions, without use of iteration, and conversely. |
|
http://www.ipedia.com/recursion.html
(986 words)
|
|
| |
| | VisualWorks: Tail Recursion |
 | | In a language where tail calls are not a requirement, they remain merely an optimization technique that may reduce memory usage of some programs. |  | | Date: 20 Aug 1996 00:00:00 GMT Tail recursion optimization is often misunderstood by newcomers and occasional spectators. |
|
http://wiki.cs.uiuc.edu/VisualWorks/Tail+Recursion
(1535 words)
|
|
| |
| | Tail Recursion |
 | | In this example, the recursive call to `myfun' is tail-recursive: (defun myfun (x) (if (oddp (random x)) (isqrt x) (myfun (1- x)))) Tail recursion is interesting because it is form of recursion that can be implemented much more efficiently than general recursion. |  | | Well, the main answer is that recursion is a more general mechanism, so it can express some solutions simply that are awkward to write as a loop. |  | | Some programmers also feel that recursion is a stylistically preferable way to write loops because it avoids assigning variables. |
|
http://cis.ksu.edu/VirtualHelp/Info/develop/cmu-user.info.Tail_Recursion.html
(594 words)
|
|
| |
| | Lab 9 Tail recursion and loops |
 | | Tail calls also permit us to forget the values of function parameters and local variables, because we never do any more work in the calling function, but a non-tail call forces us to remember such values, which might be used when we return to the calling function. |  | | Turn the helper function parameters into local variables; their initial values are the same as the initial values for the call to the helper function from the main function. |  | | In particular, if a function makes a recursive call, but then examines the result and does different things depending on its value, then it may not be possible to make the function tail-recursive. |
|
http://www.owlnet.rice.edu/~comp210/96spring/Labs/lab09.html
(1534 words)
|
|
| |
| | Squawks of the Parrot: What the heck is: A tail call |
 | | Tail calls, and their more restricted brethren tail recursion, are one of those clever optimizer tricks that were invented many years ago, then promptly forgotten by most of the mainstream language implementors. |  | | Doing tail call optimizations are also really easy for Lisp, just because of the way the language works and is structured. |  | | In procedural and OO languages the benefits are a bit smaller, since there are generally fewer function calls and more code executed between function calls, and many of the returns don't return just the result of a function call, but even then it does make a difference. |
|
http://www.sidhe.org/~dan/blog/archives/000211.html
(1302 words)
|
|
| |
| | CS153 2003S : Tail Recursion |
 | | In writing recursive procedures and looking and these procedures, you may have noticed that there are two general strategies for dealing with the result of the recursive call: (1) you can just return the result; or (2) you can do something with the result. |  | | In previous labs, we've seen several examples illustrating the idea of separating the recursive kernel of a procedure from a husk that performs the initial call. |  | | Summary: In this reading, we consider how to make your recursive procedures run more quickly by taking advantage of a program design strategy called tail recursion. |
|
http://www.math.grin.edu/~rebelsky/Courses/CS153/2003S/Readings/tail-recursion.html
(1771 words)
|
|
| |
| | tail recursion |
 | | The recursion may be optimized away by executing the call in the current stack frame and returning its result rather than creating a new stack frame. |  | | This code transformation is simple enough to do by hand in this example, but it is much harder for complex recursive data structures, such as trees. |  | | Go to the Dictionary of Algorithms and Data Structures home page. |
|
http://www.nist.gov/dads/HTML/tailrecursn.html
(258 words)
|
|
| |
| | COMP 228 > Notes on tail recursion |
 | | A function call is said to be tail recursive if there is nothing to do after the function returns except return its value. |  | | This is equivalent in effect to a "GoTo", and lets a programmer write recursive definitions without worrying about space inefficiency (from this cause) during execution. |  | | In general tail recursion and while loops can be translated without loss: |
|
http://www.yukoncollege.yk.ca/~ttopper/COMP228/TailRecursion.html
(480 words)
|
|
| |
| | Tail Recursion and Continuations |
 | | First class continuations are not a problem, since they are handled by the underlying Scheme environment. |  | | It is important that the debugger maintains this property whenever possible, because otherwise a debugged program might easily run out of memory. |  | | This would add some complexity, though, and since it would take quite a time to run out of memory by single stepping a program by hand, it has not been judged worth the effort. |
|
http://www.cs.iastate.edu/~leavens/ComS342-SICP/docs/psd/article/node8.html
(117 words)
|
|
| |
| | An Introduction to Scheme and its Implementation - Tail Recursion |
 | | Many Scheme programs rely heavily on recursion, and Scheme makes it easy to use recursion in ways that aren't feasible in most other languages. |  | | And of course, you can use recursion the way you would in most languages, as well as for loops, so recursion can do both jobs. |  | | When a procedure calls itself in a way that is equivalent to iterating a loop, Scheme automatically "optimizes" it so that it doesn't need extra stack space. |
|
http://www.cs.utexas.edu/ftp/pub/garbage/cs345/schintro-v13/schintro_73.html
(355 words)
|
|
| |
| | lua-users wiki: Proper Tail Recursion |
 | | This pattern is so that every time a function ends by returning the value of a function (including a recursive calls), the current stack frame is reused without need for consumption of stack resources. |  | | which is not tail recursion, because the last computation to do is the product of |  | | It means that for a special pattern of function calls, an optimization is done to save resources, namely the stack. |
|
http://lua-users.org/wiki/ProperTailRecursion
(361 words)
|
|
| |
| | Tail call optimization |
 | | Tail recursion using after is possible but expensive (about 50 times!) |  | | This preference leads to a style of programming where loops are replaced by recursion, and all the control structure is applicative, that is, based on function calls. |  | | NEM said that the implementation of tail should be: "proc tailcall args { return -code eval $args }". |
|
http://wiki.tcl.tk/1348
(4884 words)
|
|
| |
| | Brain.Save() - Tail recursion! |
 | | However, there’s really no semantic reason why this has to be accomplished recursively – you could do some magic behind the scenes to turn tail recursion into iteration. |  | | In a naive implementation, calls to countdown with large values of x would cause a stack overflow due to the recursive nature of the expression. |  | | The Scheme spec requires implementations to perform such magic. |
|
http://hyperthink.net/blog/PermaLink,guid,ddd56380-9418-404b-8429-7f1656127b2e.aspx
(439 words)
|
|
| |
| | tail-end recursion |
 | | As you said, your Lisp pseudocode example is cheating a bit by explicitly calling (output) on the result of the recursion, so it isn't really tail-recursion; to make it qualify, you'd need to have the body of your pseudocode generate the output and have the recursion _only_ recurse. |  | | imho optimizing tail-end recursion is _very_ significant, given that variables are "final" and there is no "return value" from templates. |  | | It's heavily used in Lisp, but Lisp also tends to recurse much more deeply; I have the impression that in most XSLT stylesheets recursion is on the order of the depth of the source document... |
|
http://www.stylusstudio.com/xsllist/200010/post40430.html
(337 words)
|
|
| |
| | CLiki : Tail Recursion |
 | | It's all very well saying do tail "elimination where possible", but you'd need a list of where, like in Scheme R5RS section 3.5, which defines where tail contexts are in terms of a subset of rules of the scheme grammar. |  | | The major concern would be that an implementation with a feature of :tail-whatever and providing a known declaration of (optimise (tail-whatever 3)) to turn it on, would at minimum comply with a particular list of valid tail contexts, provided the programmer bore in mind the list of known caveats. |  | | In a thread on c.l.l., a vague idea of pseudostandardising across implementations was raised. |
|
http://www.cliki.net/CLiki
(393 words)
|
|
| |
| | Sequence Evaluation and Tail Recursion |
 | | Even though the procedure is syntactically recursive (defined in terms of itself), it is not logically necessary for an evaluator to save information in passing from one call to |  | | For example, with tail recursion, an infinite loop can be expressed using only the procedure-call mechanism: |  | | An evaluator that can execute a procedure such as |
|
http://mitpress.mit.edu/sicp/full-text/sicp/book/node122.html
(724 words)
|
|
| |
| | Proper tail recursion Python Dev |
 | | tail recursive algorithm can usually be rewritten iteratively and b) |  | | a way to run recursion far more efficiently, then that's swell too. |  | | optimizes tail calls in the CPython interpreter, so that the stack is not |
|
http://www.gossamer-threads.com/lists/python/dev/277157?do=post_view_flat
(3625 words)
|
|
| |
| | Tail Recursion with Dynamic Scope |
 | | When applied throughout a program, this transforms tail recursions into loops; many modern languages exploit this fact by providing no explicit iteration constructs, instead letting you express control flow with procedure calls. |  | | The most natural way to interpret a dynamically-scoped language, however, generally has code between the CALL and the RETURN, spoiling the optimization. |  | | Without it, to read past a string of spaces the interpreter enters into a deep mutual recursion between |
|
http://www.accesscom.com/~darius/writings/dynatail.html
(1133 words)
|
|
| |
| | Tail Recursion Through Universal Invariants - Jay (ResearchIndex) |
 | | Abstract: Tail recursive constructions suggest a new semantics for datatypes, which allows a direct match between specifications and tail recursive programs. |  | | 1 Introduction Tail recursion is a central feature of program construction because of its... |  | | Convergent models of the natural numbers and lists are examined in detail, and, under very mild conditions, are shown to be equivalent to the corresponding initial algebra models. |
|
http://citeseer.ist.psu.edu/144023.html
(367 words)
|
|
| |
| | tail recursion - OneLook Dictionary Search |
 | | tail recursion : Free On-line Dictionary of Computing [home, info] |  | | tail recursion : Dictionary of Algorithms and Data Structures [home, info] |  | | Tip: Click on the first link on a line below to go directly to a page where "tail recursion" is defined. |
|
http://www.onelook.com/cgi-bin/cgiwrap/bware/dofind.cgi?word=tail+recursion
(104 words)
|
|
| |
| | Joe Marshall on Rebol 1.0 |
 | | Nonetheless, I don't see an easy way of achieving tail-recursion otherwise. |  | | Let us explore the problem by writing a toy rebol interpreter in Scheme. |  | | When evaluating a sequence of expressions in a block, we recursively evaluate the first expression in the sequence obtaining its value and the `remaining' part of the block. |
|
http://ll1.ai.mit.edu/marshall.html
(1938 words)
|
|
| |
| | Prolog: Conversion to tail recursion: exponentiation |
 | | A good example of this is the original factorial program. |  | | , where exp will require 1000 distinct solution variables as it goes into the recursion.) When the final recursive call is made, the solution found then is the overall solution. |  | | With a recursion, the obvious program - the one which is the most direct transcription of the pure logical definition - tends, when used, to generate a stack of uninstantiated variables. |
|
http://www.mdx.ac.uk/www/psychology/cog/psy3230/exponen.htm
(810 words)
|
|
| |
| | Proper Tail Recursion |
 | | This gives us a precise definition of iteration: a repetitive program that does not create a growing context on the stack; in other words, a properly tail recursive program. |  | | That context must be saved somehow or else we lose the computation. |  | | A proper tail recursive call to G never returns to its caller F, yet the computation can proceed as though it had. |
|
http://www.cs.oberlin.edu/~rhyspj/classes/rit/abstrprac/lab9/lab9510.html
(243 words)
|
|
| |
| | Unrolling loops and tail recursion - |
 | | I have no idea how to implement tail recursion elimination, and I'd dearly love to learn. |  | | Unrolling of loops is something that becomes important for compiling to standalone executables; I think |  | | Tail recursion elimination is something which has been on the todo for a long time, but I think nobody's done it because it's really really hard. |
|
http://dev.perl.org/perl6/rfc/302.html
(103 words)
|
|
| |
| | Diagnosing Java Code: Improve the performance of your Java code |
 | | The solution is relatively simple: because these tail-recursive functions are really just easier ways of writing loops, have the compiler automatically transform them to loops. |  | | An example: Static compilation can't optimize the tail call |  | | Imagine how confusing it would be to compile this code with two different static compilers, only to find that the resulting code threw an exception in one case and not in the other. |
|
http://www-128.ibm.com/developerworks/java/library/j-diag8.html
(1407 words)
|
|
| |
| | Tail recursion modulo cons - Computing Reference - eLook.org |
 | | Tail recursion modulo cons - Computing Reference - eLook.org |  | | This is transformed into a tail call to the function which is also passed a pointer to where its result should be written. |  | | It applies when the last thing a function does is to apply a constructor functions (e.g. |
|
http://www.elook.org/computing/tail-recursion-modulo-cons.htm
(135 words)
|
|
| |
| | Tail recursion optimisation - Computing Reference - eLook.org |
 | | Tail recursion optimisation - Computing Reference - eLook.org |  | | This is important when a procedure calls itself recursively many times for, without tail recursion optimisation, the environments of earlier invocations would fill up the memory only to be discarded when (if) the last call terminated. |  | | It allows recursive functions to be compiled into iterative loops. |
|
http://www.elook.org/computing/tail-recursion-optimisation.htm
(114 words)
|
|
| |
| | Tail Recursion Exceptions |
 | | Shallow-binding implementations of dynamic scoping also require cleanup code to be evaluated when the scope is exited. |  | | These dynamic extent binding forms inhibit tail recursion because they allocate stack space to represent the binding. |
|
http://www.cis.ksu.edu/VirtualHelp/Info/develop/cmu-user.info.Tail_Recursion_Exceptions.html
(34 words)
|
|
| |
| | Tail recursion optimization |
 | | The optimization applies to all tail calls, not just recursive ones |  | | If a function f calls a function g and immediately returns the result of g, the generated code can destroy f's local variables and return address before calling g |
|
http://www.cs.princeton.edu/courses/archive/spr98/cs333/lectures/16/tsld011.htm
(40 words)
|
|
| |
| | Tail Recursion |
 | | Although more difficult than simple tail recursion, it is also possible to optimize a() calls b() calls a() tail recursion. |  | | Tail recursion can significantly improve the performance of small recursive benchmarks such as Hanoi. |  | | Below is the code fragment after tail recursion. |
|
http://www.nullstone.com/htmls/category/tailrec.htm
(126 words)
|
|
| |
| | Digital Mars - D - Tail recursion? |
 | | I never was very much into excessively recursive programming style, so |  | | I wouldn't expect many designers of imperative languages to count on |  | | if it went out of its way to disallow this special case of recursion. |
|
http://www.digitalmars.com/d/archives/28361.html
(1043 words)
|
|
| |
| | Geneseo CSci 331 Tail Recursion Optimization |
 | | A simple (but not all that common) example of optimization: tail recursion elimination. |  | | Replace a recursive call that is the very last thing a function does with a jump to the function's entry point -- turns recursion into looping. |  | | Tail recursion elimination loses multiplication by n after call |
|
http://www.cs.geneseo.edu/~baldwin/csci331/spring2002/tailrec.html
(410 words)
|
|
| |
| | Tail Recursion |
 | | None of the above examples of recursive functions are tail recursive. |  | | If you get to the stage of compiling your LISP code (a compiler takes code in a programming language and turns it into binary machine language to make it run faster) some compilers are smart enough to distinguish tail-recursive processes from those that are not. |  | | When compiling LISP code, a ``smart'' compiler is capable of recognizing tail recursion, and cutting off processing as soon as the lowest level returns. |
|
http://grimpeur.tamu.edu/~colin/lp/node38.html
(262 words)
|
|
| |
| | [plt-scheme] begin0 and tail recursion |
 | | Robby At Sun, 20 Jul 2003 08:59:37 -0500, Robby Findler wrote: > For list-related administrative tasks: > http://list.cs.brown.edu/mailman/listinfo/plt-scheme > > It isn't a tail call because it must evaluate E1, then evaluate E2, and > then return E1's result. |  | | You'll purple arrows that show you the syntactic tail call behavior of the program. |  | | > > >> > > >> > > >> > > > > > > > > > > > > > > > > ------------------------------------------------------------------------------ > > It doesn't tail call because it evaluates x first, right? |
|
http://www.cs.brown.edu/pipermail/plt-scheme/2003-July/003199.html
(328 words)
|
|
| |
| | Comp.compilers: Tail recursion |
 | | Reason I ask: For some algorithms, the recursive formulation is |  | | Scheme compilers are of course required by the IEEE Scheme |  | | processing on the result from the recursion, beyond passing it back to |
|
http://compilers.iecc.com/comparch/article/00-08-054
(102 words)
|
|
| |
| | [REBOL] Re: Tail recursion in REBOL 2.0 |
 | | Sure, you could do it by looking forward some bytes o> (seeing that there isn't anything more to do in the body of o> the function), but if you should do this properly, program o> execution will probably be slowed down. |  | | I'd prefer a better solution, such as testing for tail recursion only on function that require it: f: tail-recursive-func [...] [...] Regards, Gabriele. |  | | I'd like to see tail recursion back in REBOL, but I'm not sure if I'd want the complexity of the interpreter to increase. |
|
http://www.mail-archive.com/list@rebol.com/msg01982.html
(194 words)
|
|
| |
| | Tail Recursion |
 | | Using an accumulator argument, but not using explicit list reversal, give rules for a function which converts from binary to a natural number when the binary is represented as a list |  | | The type of recursion displayed by reverse using an accumulator, where there are no further operations to be performed on the rewritten result, is called |  | | Give rules for the function qsort (abbreviation for "Quicksort") which sorts a list by the following recursive method: |
|
http://www.cs.hmc.edu/claremont/keller/webBook/ch04/sec12.html
(594 words)
|
|
| |
| | Proper Tail Recursion and Space Efficiency - Clinger (ResearchIndex) |
 | | To appear in Proceedings of the 1998 ACM Conference on Programming Language Design and Implementation, June 1998. |  | | This ensures that portable code can rely upon the space efficiency of continuation-passing style and other idioms. |  | | Typically, determining if a procedure call is tail recursive is a simple syntactic test. |
|
http://citeseer.ist.psu.edu/102345.html
(564 words)
|
|
| |
| | blink182.ca - Tail Light |
 | | Save time & money every time you shop online: DealTime is a free comparison-shopping service that helps you find the Web's best prices on links to everything from Computers & Electronics to Jewelry, Toys & more. |  | | Here are some other items you may be interested in. |  | | We couldn't find any results for Tail Light in Music. |
|
http://www.blink182.ca/Tail-Light/reference/search
(280 words)
|
|
| |
| | Tail recursion always possible? |
 | | in let c = f(a) in let d = f(b) in some_operation(c, d) Since c and d have to be computed in terms of recursive calls, and some_operation _has_ to be applied in terms of c and d, I have trouble seeing how the use of accumulators would solve this. |  | | I wonder if these types of programs can be made tail-recursive at all, or if there's something I'm just not seeing? |
|
http://www.talkaboutprogramming.com/group/comp.lang.ml/messages/7482.html
(146 words)
|
|
| |
| | Tail recursion - Computing Reference - eLook.org |
 | | A function may make several recursive calls but a call is only tail-recursive if the caller returns immediately after it. |  | | Here the both calls to fib are recursive but only the outer one is tail recursive. |  | | See tail recursion optimisation, and, if you aren't sick of them already, recursion, tail recursion. |
|
http://www.elook.org/computing/tail-recursion.htm
(80 words)
|
|
| |
| | 3.3.5 Debug Tail Recursion |
 | | Both the compiler and the interpreter are ``properly tail recursive.'' If a function call is in a tail-recursive position, the stack frame will be deallocated ıat the time of the call, rather than after the call returns. |  | | If there is any doubt about how one function called another, it can usually be eliminated by finding the source location in the calling frame (section 3.5.) |  | | For a more thorough discussion of tail recursion, see section 5.5. |
|
http://www.ifi.uio.no/~kt-lab/lambdalab/doc/CMUCL/node67.html
(115 words)
|
|
| |
| | Tail recursion example |
 | | the call to f is a tail call, but the call to g is not |
|
http://www.cs.princeton.edu/courses/archive/spring98/cs333/lectures/16/sld012.htm
(15 words)
|
|
| |
| | Re: Tail recursion always possible? |
 | | Haakon Nilsen wrote: [...] > I wonder if these types of programs can be made tail-recursive at all > [...] In general, you can convert recursive functions to continuation passing style (CPS), which is tail recursive. |
|
http://www.talkaboutprogramming.com/group/comp.lang.ml/messages/7490.html
(106 words)
|
|
| |
| | jargon, node: tail recursion |
 | | tail recursion /n./ If you aren't sick of it already, see tail recursion. |
|
http://www.jargon.net/jargonfile/t/tailrecursion.html
(13 words)
|
|
| |
| | Tail recursion - Uncyclopedia |
 | | This page was last modified 22:40, 16 Apr 2005. |  | | If you aren't sick of it already, see tail recursion. |
|
http://www.uncyclopedia.org/wiki/Tail_recursion
(27 words)
|
|
| |
| | tail recursion |
 | | If you aren't sick of it already, see tail |
|
http://sunsite.informatik.rwth-aachen.de/jargon300/tailrecursion.html
(9 words)
|
|
|