csharplang icon indicating copy to clipboard operation
csharplang copied to clipboard

[Proposal]: `tail return` recursive calls

Open 333fred opened this issue 11 months ago • 0 comments

tail return recursive calls

  • Specification: In the discussion for now
  • Discussion: https://github.com/dotnet/csharplang/discussions/8990

Summary

There are a number of instances where it may be clearer to express your algorithm via recursion, especially tail recursion, but unfortunately all recursion in C# currently requires O(n) space for just the call stack, meaning that your algorithm cannot take less than O(n) space.

It is proposed that C# provide a new statement form and a new expression form to allow tail-recursive calls to consume O(1) space.

Design meetings

333fred avatar Jan 06 '25 22:01 333fred