-1

I am unsure if the following statements make sense:

  1. Invoking a non-tail-recursive function in a functional programming languages has, typically, a space efficiency problem due to growing call stacks.

  2. Each non-tail-recursive function can be systematically transformed to a tail-recursive one by transforming the function call to continuation-passing style.

  3. Continuation-passing style is the rescue for functional programming languages because without it, non-tail-recursive functions which prevail in code base of functional programming languages would necessarily cause significant performance issues.

zell
  • 9,830
  • 10
  • 62
  • 115

1 Answers1

2

This is totally wrong. While every function can by systematically transformed into on that use continuation passing style, this does not solve space efficiency problems of an algorithm. The space might be allocated in the continuation closure instead of on the execution stack, but that makes no difference.

(Also, this has nothing do with a language being functional or not.)

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
  • So, you were saying continuation passing style does not solve space efficiency problems. Does tail-recursive function solve space efficiency problems? Or could you elaborate a bit more for beginners? – zell Nov 04 '20 at 13:52
  • Tail call optimisation prevents unnecessary call stack growth. Nothing more, nothing less. It can't do anything about *necessary* stack growth, and it definitely doesn't "*solve space efficiency problems*" in general. – Bergi Nov 04 '20 at 14:22