Tail recursion Functional Programming
Page 1 of 12 Replies - 2450 Views - Last Post: 09 July 2010 - 01:19 PM
#1
Tail recursion Functional Programming
Posted 08 July 2010 - 07:25 PM
To construct a for loop in a functional programming language you have to use recursion. I have heard that tail recursion does not overflow the stack. When ever a function call's itself a new stack frame is inserted but how come on this scenario the stack does not overflow?
Replies To: Tail recursion Functional Programming
#2
Re: Tail recursion Functional Programming
Posted 09 July 2010 - 05:59 AM
This doesn't apply to all functional languages. for loops are usually not included in functional languages due to recursion being more general and useful, and rarely even needed thanks abstractions like reduce and left and right folds.
What you are thinking of is something that some languages have, called "tail call optimization". This is a feature some languages have that make the compiler detect "tail-calls", which are recursive calls that are the last operation done in the function. This type of recursion can be changed by the compiler to iterations easily, and this will take up much much less stack space than normal recursion.
You can find information about this in much more detail here: http://en.wikipedia..../Tail_recursion
What you are thinking of is something that some languages have, called "tail call optimization". This is a feature some languages have that make the compiler detect "tail-calls", which are recursive calls that are the last operation done in the function. This type of recursion can be changed by the compiler to iterations easily, and this will take up much much less stack space than normal recursion.
You can find information about this in much more detail here: http://en.wikipedia..../Tail_recursion
#3
Re: Tail recursion Functional Programming
Posted 09 July 2010 - 01:19 PM
Moved to Functional Programming
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|