Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative mechanism for recursive function literals #1120

Open
degory opened this issue Mar 16, 2024 · 0 comments
Open

Alternative mechanism for recursive function literals #1120

degory opened this issue Mar 16, 2024 · 0 comments

Comments

@degory
Copy link
Owner

degory commented Mar 16, 2024

Where function literals are immediately assigned to a variable in a let statement, we could automatically capture their self value. We could also support mutual recursion where multiple literal functions are bound to variables all in the same let statement. For example

let 
    is_even = (n: int) => if n == 0 then true else is_odd(n - 1) fi,
    is_odd = (n:int)  => if n == 0 then false else is_even(n - 1) fi;

This wouldn't be a replacement for rec because there are still scenarios where you might want a function literal to be recursive without having to explicitly bind it to a variable with a let statement (i.e. passing it as an argument to another function)

We'd need to ensure that the right hand sides are each only function literals, and arrange to create their all their frames and delegates, before then injecting each delegate into all the others as an additional capture

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant