2 Replies - 2676 Views - Last Post: 09 July 2010 - 01:19 PM

#1 Ario7X  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 26
  • Joined: 24-April 10

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? :helpsmilie:
Is This A Good Question/Topic? 0
  • +

Replies To: Tail recursion Functional Programming

#2 Raynes  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 611
  • View blog
  • Posts: 2,815
  • Joined: 05-January 09

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
Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Tail recursion Functional Programming

Posted 09 July 2010 - 01:19 PM

Moved to Functional Programming
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1