Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Implement rec keyword and support #27

Closed
mrkmarron opened this issue Apr 18, 2019 · 2 comments · Fixed by #185
Closed

Implement rec keyword and support #27

mrkmarron opened this issue Apr 18, 2019 · 2 comments · Fixed by #185
Assignees
Labels
enhancement New feature or request

Comments

@mrkmarron
Copy link
Contributor

Implement the rec keyword and support. I would like to do CPS conversion so we always have a bounded stack.

@mrkmarron mrkmarron added the enhancement New feature or request label Apr 18, 2019
@clegoz
Copy link
Contributor

clegoz commented Apr 29, 2019

I've implemented some of it. Currently supports only namespace functions. I don't think is ready but it should be enough for testing/education. You could clone it from here. (commit)

Example:

namespace NSMain;

function incrementRecursive(n: Int, max: Int): Int {
    _debug(n);
    return n < max ? rec incrementRecursive(n + 1, max): n;
}

entrypoint function main(): Bool {
    var test = incrementRecursive(1, 99999999);
    return true;
}

@orcmid
Copy link

orcmid commented Apr 29, 2019

I'm surprised to see rec, if needed at all, on the reference rather than the declaration.

Although function rec f( ... ) ... was a common idea, it seems that practice involves function recursiveness being the default with regard to static name resolution within lexical structure. That seems to be the approach with SML, and it tends to be more natural. It does require some trickery when the inner call is intended to be to an outer declaration, not the current one.

The additional case of mutual recursion has to be handled a different way.

There also needs to be something else for anonymous function definitions.

I should zip my lip until I look more closely at the Bosque definition material.

Also, I thought this notion is independent of the question of tail recursion. Am I mistaken?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants