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

Proper tail recursion #728

Closed
wants to merge 9 commits into
base: master
from

Conversation

Projects
None yet
4 participants
@Tritlo
Contributor

Tritlo commented Dec 21, 2014

I've added support for Proper tail recursion in Hy. It's optional, and can be enabled with an

(import [__future__ [TailRec]])

in the Hy source where it is needed. Benefits can be seen for example in the tests, where we can use mutual recursive functions (not just self recurring, as the current loop macro implements) on much larger values without hitting a recursion depth exceeded exception.

Needs a little more work before it can be in Hy proper, as it does not work while bootstrapping (since the TailCall mechanism itself is written in Hy).

@Tritlo Tritlo changed the title from Proper tail recursion in Hy to Proper tail recursion Dec 21, 2014

@Tritlo Tritlo referenced this pull request Dec 30, 2014

Closed

Return expression #739

@paultag

This comment has been minimized.

Show comment
Hide comment
@paultag

paultag Jan 11, 2015

Member

Interesting approach!

Member

paultag commented Jan 11, 2015

Interesting approach!

@paultag

This comment has been minimized.

Show comment
Hide comment
@paultag

paultag Jan 11, 2015

Member

I'll get on a more in depth review with how this is structured, since this adds a bunch of new things to internals. Very cool work, though!

Member

paultag commented Jan 11, 2015

I'll get on a more in depth review with how this is structured, since this adds a bunch of new things to internals. Very cool work, though!

Tritlo added some commits Jan 14, 2015

Merge branch 'master' of git://github.com/hylang/hy
* 'master' of git://github.com/hylang/hy:
  Correct indentation level of code blocks
  Miscellaneous fixes to transplanted style guide
  Match heading/subheading style to rest of Hy docs
  Transplant style guide from hylang/hy-style-guide
Merge branch 'master' of github.com:hylang/hy
* 'master' of github.com:hylang/hy:
  Add Shenyang Zhao to AUTHORS
  add documents for symbol?
  add `symbol?` function to `hy.core`
  Fix completion bugs
  fix typos in koan
  Adding Shrayas to AUTHORS
  Adapt attribute completion from IPython completer
  Added a fix for nested decorators. Fixes #752
  Fix typo
@Tritlo

This comment has been minimized.

Show comment
Hide comment
@Tritlo

Tritlo Jun 11, 2015

Contributor

So, any news?

Contributor

Tritlo commented Jun 11, 2015

So, any news?

@paultag

This comment has been minimized.

Show comment
Hide comment
@paultag

paultag Jun 11, 2015

Member

Ah, yes, the news is I'm literally the worst.

Let's get eyes on this and tend to it - ping @hylang/core

Member

paultag commented Jun 11, 2015

Ah, yes, the news is I'm literally the worst.

Let's get eyes on this and tend to it - ping @hylang/core

Show outdated Hide outdated hy/compiler.py Outdated
@paultag

This comment has been minimized.

Show comment
Hide comment
@paultag

paultag Jul 22, 2015

Member

Interesting approach, using Exceptions. The overhead on this might slow it down, but short of crosscutting into Bytecode, we can't have GOTO/JUMP instructions.

This is pretty similar (but not similar enough to merge with) https://github.com/hylang/hy/blob/master/hy/contrib/loop.hy -- not sure which I like more.

Can we move this to contrib to start with? This is a total no brainer for contrib right now, but I'd love to battle test this a little before putting it into core.

Really interesting work. I like it. Well done, @Tritlo

Member

paultag commented Jul 22, 2015

Interesting approach, using Exceptions. The overhead on this might slow it down, but short of crosscutting into Bytecode, we can't have GOTO/JUMP instructions.

This is pretty similar (but not similar enough to merge with) https://github.com/hylang/hy/blob/master/hy/contrib/loop.hy -- not sure which I like more.

Can we move this to contrib to start with? This is a total no brainer for contrib right now, but I'd love to battle test this a little before putting it into core.

Really interesting work. I like it. Well done, @Tritlo

@Tritlo

This comment has been minimized.

Show comment
Hide comment
@Tritlo

Tritlo Jul 23, 2015

Contributor

This is actually more powerful than loop, since it allows mutually recursive functions. I'm not sure that this can be moved into contrib, since we need access to the expressions themselves when we convert the return into an exception. This is needed to break out of the stack, and avoid a stack overflow. This also allows us to have tail recursive functions within other tail recursive functions, without any additional overhead.

The overhead can definitely slow this down, which that is why we use the from future expression, to avoid the overhead where we can.

Contributor

Tritlo commented Jul 23, 2015

This is actually more powerful than loop, since it allows mutually recursive functions. I'm not sure that this can be moved into contrib, since we need access to the expressions themselves when we convert the return into an exception. This is needed to break out of the stack, and avoid a stack overflow. This also allows us to have tail recursive functions within other tail recursive functions, without any additional overhead.

The overhead can definitely slow this down, which that is why we use the from future expression, to avoid the overhead where we can.

@paultag

This comment has been minimized.

Show comment
Hide comment
@paultag

paultag Dec 12, 2015

Member

Merge conflicts against master - mind updating? I'm going to close this until it's ready :)

👍

Member

paultag commented Dec 12, 2015

Merge conflicts against master - mind updating? I'm going to close this until it's ready :)

👍

@paultag paultag closed this Dec 12, 2015

@bowbahdoe

This comment has been minimized.

Show comment
Hide comment
@bowbahdoe

bowbahdoe Dec 8, 2016

Is there any reason that this has been neglected for a year? It seems like a tremendously useful feature.

bowbahdoe commented Dec 8, 2016

Is there any reason that this has been neglected for a year? It seems like a tremendously useful feature.

@Kodiologist

This comment has been minimized.

Show comment
Hide comment
@Kodiologist

Kodiologist Dec 8, 2016

Member

Apparently, nobody cared enough to fix the merge conflicts. Feel free to make a new PR out of this if you want to do it.

Member

Kodiologist commented Dec 8, 2016

Apparently, nobody cared enough to fix the merge conflicts. Feel free to make a new PR out of this if you want to do it.

@Tritlo

This comment has been minimized.

Show comment
Hide comment
@Tritlo

Tritlo Dec 8, 2016

Contributor

Oofh. I've been very busy the last year, and haven't had time to take care of this pull request. It's been ready for about 2 years now, and there never seems to be interest in actually getting it into the Hy language. I'll try to look into it over christmas if possible, but I'm afraid that I haven't been following Hy's development for a long time, so I might need some help. Is there still interest for this feature, @paultag @Foxboron ?

Contributor

Tritlo commented Dec 8, 2016

Oofh. I've been very busy the last year, and haven't had time to take care of this pull request. It's been ready for about 2 years now, and there never seems to be interest in actually getting it into the Hy language. I'll try to look into it over christmas if possible, but I'm afraid that I haven't been following Hy's development for a long time, so I might need some help. Is there still interest for this feature, @paultag @Foxboron ?

@bowbahdoe

This comment has been minimized.

Show comment
Hide comment
@bowbahdoe

bowbahdoe Dec 8, 2016

Looking at the source now, the actual areas this changed haven't been updated that much. I'm not well versed in git, but if I insert the changes again on an updated branch that should get rid of merge conflicts.

bowbahdoe commented Dec 8, 2016

Looking at the source now, the actual areas this changed haven't been updated that much. I'm not well versed in git, but if I insert the changes again on an updated branch that should get rid of merge conflicts.

@Tritlo

This comment has been minimized.

Show comment
Hide comment
@Tritlo

Tritlo Dec 8, 2016

Contributor

I'll see whether I can patch this up real quick.

Contributor

Tritlo commented Dec 8, 2016

I'll see whether I can patch this up real quick.

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