develooper Front page | perl.perl5.porters | Postings from January 2008

Re: For 5.12: tail calls for methods

Thread Previous | Thread Next
Aaron Crane
January 17, 2008 09:44
Re: For 5.12: tail calls for methods
Message ID:
Michael G Schwern writes:
> Why isn't Perl doing [tail call merging] automatically again?  Can't
> it see when the return from a subroutine call is going to be the
> last evaluated expression?

I don't know the history of how we got here, but one reason not to
apply tail-call merging automatically is that it's likely to break

Providing specific syntax for doing tail calls would help with that:
if you ask for tail-call frames to be merged with caller frames,
you're also asking for those caller frames to be unavailable for
introspection (or at the very least saying that you're willing for
them to be unavailable).

Such syntax could perhaps be

  use less 'stack';             # lexically scoped
  sub foo {
      return $coderef->(@args); # tail call merged implicitly


  use feature 'tail_return';
  sub foo {
      tail_return $coderef, @args;

Hmm.  Looking at that last one, I'm now wondering if a tail_return
pseudo-function could be written in XS.

Aaron Crane

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About