Hi everyone,

In order for me to understand tail recursion with a sample as simple as possible would anybody put a tail recursion version of the following funcion?

Stacked version of Reverse ( Text ):

Case (

Length ( Text ) > 1 ;

Reverse ( Right ( Text ; Length ( Text ) - 1 ) ) & Left ( Text ; 1 ) ;

Text

)

Thank you very much in advance.

Kind regards,

Miguel

I think all functions, yours and both the functions suggested bij beverly are head-recursion. After 10000 iterations the result from any of them will be "?".

The following function has tail-recursion and will run not out of memory, (but after 50000 iterations FM stops calculating and give a "?" for result):

The difference between head- and tail-recursion is:

with

head-recursion, the result of each iteration is concatenated to the first iteration, Like: Reverse ( "ABCD" ) & Reverse ( "ABC" ) & Reverse ( "AB" ) & "A" and result is returned at the end of all iterations. This consumes more memory each iteration.with

tail-recursion, the result is stored in a separate address in memory, which is overwritten in each iteration. Hence the always empty second "Result" parameter, which only serves as a placeholder for the result of the calc.