[Proposal] Recur keyword for tail call recursion.
- Dominant language
- No language data
- Stars
- 328
- Forks
- 71
- PR merge metrics
- No merged PRs in 30d
Description
Tail call recursion is a already exit feature in .net framework and .net core but rarely apply for other then F#, I propose Recur keyword for apply in VB.net.
## Syntax
```vb
Function Factorial(Input As Int32) As Int32
Dim Output = 2
Recur Until Input < 3
Output *= Input
Input -= 1
End Recur
Return Output
End Function
```
Adapt from `Do Loop` statement because it's very close to recursion.
## How does it work ?
To make Recur keyword working, it need to split into 2 lambda expression methods.
1. Checking exit condition method.
2. Recursion method.
```vb
Private Output As Int32 = 2
Function Factorial(Input As Int32) As Int32
If Function() Input < 3 Then
Sub()
Output *= Input
Input -= 1
End Sub
Return Tail Call Factorial(Input)
Else
Return Output
End If
End Function
```
Lambda expression method is create a anonymous class store method include all variant input into it.
## How to do it without this keyword ?
You can write it with a dynamic method or try it with [Extend Standard Library](https://github.com/RevensofT/exs).
```vb
Import EXS
Function Factorial(Input As Int32) As Int32
Return (I:=Input, O:=2).do(
Function(Arg) Arg.I < 3,
Function(Arg) (Arg.I - 1, Arg.O * Arg.I)
).O
End Function
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.