csharplang
csharplang copied to clipboard
[Proposal]: `tail return` recursive calls
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.