Home

Advertisement

A good explanation of Tail Recursion

  • Oct. 22nd, 2008 at 9:19 PM
Chris Smith has a very straight forward explanation of tail recursion:
Tail Recursion is a specialized type of recursion where there is a guarantee that nothing is left to execute in the function after a recursive call. In other words, the function returns the result of a recursive call.

If there is no additional instructions to execute, then there is no need to store the instruction pointer on the stack, since the only thing left to do once the recursive call exits is restore the stack. So rather than needlessly modifying the stack, tail calls use a GOTO statement for the recursion. And once the recursion eventually succeeds the function will return to the original instruction pointer location.

He also uses F# to write the sample code: A succinct, type-inferred, expressive, efficient functional and object-oriented language for the .NET platform.

From Miguel de Icaza's blog entry about Lang.NET Symposium:
Compiling Ruby is challenging for a number of reasons, the lack of a language specification means that sometimes the only specification for the behavior is the source code and because Ruby has a lot of features that do not map easily into the single-hierarchy, multiple-interface object model that is part of .NET. So Ruby.NET has to generate a number of helper classes and runtime support to provide the expected behavior.
It's sad to hear that Ruby has not yet a formal specification.



That reminds me a study made by a now Google engineer with 18 languages targeted at the JVM. There are script languages, some with functional features (like closures), others with class based Object Oriented paradigm, others like Javascript with a prototyped OO approach and even one Lisp like.

Latest Month

November 2009
S M T W T F S
1234567
891011121314
15161718192021
22232425262728
2930     

Tags

Syndicate

RSS Atom
Powered by LiveJournal.com
Designed by Tiffany Chow