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

Re: For 5.12: tail calls for methods

Thread Previous | Thread Next
From:
Aaron Crane
Date:
January 17, 2008 09:44
Subject:
Re: For 5.12: tail calls for methods
Message ID:
20080117174422.GV7624@aaroncrane.co.uk
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
`caller`.

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
  }

or

  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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About