Gentlemen
the languages that do not support tail call and recursions might lead to stackoverflow
cant the while or goto within the function accomplish the same task. surely with goto
one can reset the variables with certain checks when function code is about to be re-executed
i do understand that the calling of function from within itself might come handy in certain cases.
but is there something specific about it that cant be done with goto/while.
i am currently trying to get elements in array through reflection but am unable to get the desired results yet.
in that recursion does come handy when a array has array`s within. so if array has that many arrays within itself
that function recursion might cause stackoverflow i used goto. now fear of stackoverflow is not there. but i was wondering
is there something specific to recursion.
ThankingYou
RIGHT_THEN
Forums
cant goto or while replace recursions
2 posts
• Page 1 of 1
Re: cant goto or while replace recursions
My thoughts on the subject:
-- Even when a language supports tail recursion, it may suffer a stack overflow in those cases where there is no tail call to be optimized. Only a tail-call-type of recursion will escape potential stack overflow.
-- When I ran a test on Cobra on Mono 2.10.1 on Mac, it took 165,713 recursive calls before the stack overflowed. Of course, it might take less if your method has a lot of arguments and/or local variables.
-- In practice, my stack overflows have always been bugs, not limitations that prevented me from doing real work.
-- You can always replace a recursive call with your own loop and either manage your own heap-based stack if you need one, or skip it if you don't. You said you used "goto" for your loop--I presume you're using C# or some other language. You can also loop with "while true" in Cobra or any language with a "while" statement.
HTH. Here is my code:
-- Even when a language supports tail recursion, it may suffer a stack overflow in those cases where there is no tail call to be optimized. Only a tail-call-type of recursion will escape potential stack overflow.
-- When I ran a test on Cobra on Mono 2.10.1 on Mac, it took 165,713 recursive calls before the stack overflowed. Of course, it might take less if your method has a lot of arguments and/or local variables.
-- In practice, my stack overflows have always been bugs, not limitations that prevented me from doing real work.
-- You can always replace a recursive call with your own loop and either manage your own heap-based stack if you need one, or skip it if you don't. You said you used "goto" for your loop--I presume you're using C# or some other language. You can also loop with "while true" in Cobra or any language with a "while" statement.
HTH. Here is my code:
# took 165,713 recursive calls to overflow
# using Cobra on Mono 2.10.1 on Mac
# 2011-04-22
class X
var _count = 0
def main
_count += 1
File.writeAllText('count.text', _count.toString + '\n')
.main
- Charles
- Posts: 2515
- Location: Los Angeles, CA
2 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 44 guests