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

Re: For 5.12: tail calls for methods

Thread Previous | Thread Next
Stevan Little
January 17, 2008 10:06
Re: For 5.12: tail calls for methods
Message ID:

On Jan 17, 2008, at 12:44 PM, Aaron Crane wrote:
> 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).

Perhaps we not look at this a replacement for goto as much as just  
something to do automagically for recursion only. This would confine  
it to 1) it's most common use case and 2) not destroy as much of the  
introspectability of the caller output.

Then they wouldn't really have to be unavailable, they could just be  
marked as 'tail-called' in some way, I mean caller returns a whole  
bunch of extra information when called as caller(EXPR), whats one  
more ;)

Honestly I suspect the people doing hardcore introspection of the  
call stack will be able to understand "this was tail-called" and be  
able to adjust for it. The benefits of tail-call optimization I think  
would more than outweigh the lack of introspectability, and this is  
speaking as someone who both loves recursion and stack traces. Anyone  
who has experienced the insantity a stack trace from a recursive sub  
I am sure would tend to agree with me.

- Stevan

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