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

Recursion with Subroutines #11

Open
vmaddur opened this issue May 5, 2020 · 3 comments
Open

Recursion with Subroutines #11

vmaddur opened this issue May 5, 2020 · 3 comments

Comments

@vmaddur
Copy link

vmaddur commented May 5, 2020

I understand that the EV3 offers support for subroutines, but I was wondering whether they are able to be recursive themselves and/or mutually recursive. I checked out some of the programs in the test data and the documentation, and I was not able to find any information that suggested that is or isn't possible. Could you please clarify this?

@dlech
Copy link
Member

dlech commented May 5, 2020

It is not technically possible to do recursion with the current EV3 firmware. If a subcall is running and a second instance of the same subcall is called, it blocks until the first instance ends. So trying to call a subcall recursively results in a deadlock.

@vmaddur
Copy link
Author

vmaddur commented May 5, 2020

Is there a possible work-around for creating a subcall that acts in a recursive manner? That is, can we make a subcall call itself without using the call keyword directly or some kind of mutual recursion?

@dlech
Copy link
Member

dlech commented May 5, 2020

Not that I know of.

It might be possible to do "tail call" recursion where one subcall completes before the next is started.

Or maybe code could be devised to push and pop local variables and the program counter from a stack and use the jump instruction to restart a subcall without exiting it.

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

No branches or pull requests

2 participants