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

Re: For 5.12: tail calls for methods

Thread Previous | Thread Next
From:
Stevan Little
Date:
January 17, 2008 10:47
Subject:
Re: For 5.12: tail calls for methods
Message ID:
64ECADA0-471B-434B-89B1-FAC0C7BD7AB8@iinteractive.com

On Jan 17, 2008, at 1:23 PM, Aristotle Pagaltzis wrote:
> * Stevan Little <stevan.little@iinteractive.com> [2008-01-17 19:10]:
>> Perhaps we not look at this a replacement for goto as much as
>> just something to do automagically for recursion only.
>
> And how do you want to detect that?

Simple, if the last call is to the same function, then it tail-recurses.

> And how would that apply to
> more complex scenarios, eg. a mutually recursive pair of
> functions?

If they fit the above criteria then it just works, if not, they don't  
get it.

> (To say nothing of real-world scenarios like language-
> level recursive parsers where each recursion cycle may involve
> a different set of functions.)

Punt on this one, cause you would likely want to have control in this  
situation already and not want something done automagically for you.

> No, the right way of going about this is to provide alternative
> syntax that combines `goto &SUB` with putting things in `@_` such
> that the result looks just like a regular call, except for the
> new keyword or whichever syntax signifies the tail call.

But why make easy things (foo is calling foo as it's last thing, lets  
tail-recurse) hard? I understand making hard things (your more  
complex examples above) hard, but why not make simple things just work?

- Stevan

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