News for hackers. Stuff that matters.
Re:Don’t Think, Just Defunctionalize by mannykannot on Wednesday December 23, 2020 @10:59AM (#25518923)
Calculating the nth member of the Fibonacci sequence is a commonly-used example of where a naive, literal-translation-to-code recursive solution is inordinately costly - so now I am trying to figure out if the method described in this article, applied mechanically to the literal recursive solution, results in an efficient solution, or merely tranfers the data complexity of its stack frames to the heap (I think you are suggesting it would result in the latter, which seems plausible to me.)
Re:Don’t Think, Just Defunctionalize by ufo on Wednesday December 23, 2020 @04:30PM (#25522442)
The mechanical transformation described in the article does not change the asymptotic complexity of the program. It just changes it from using an implicit (recursion) stack, to using an explicit stack.

The neat thing about that transformation, in my opinion, is that it works even for complicated algorithms. Sometimes you really do need to rewrite something to use an explicit stack, and that can be quite tricky to get right!

Re:Don’t Think, Just Defunctionalize by mannykannot on Thursday December 24, 2020 @09:17AM (#25527609)
Point taken - thanks!
Re:Don’t Think, Just Defunctionalize by jpcooper on Wednesday December 23, 2020 @01:06PM (#25520260)