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

Re: Can Perl do tail recursion?

Thread Previous
Simon Cozens
January 24, 2001 11:30
Re: Can Perl do tail recursion?
Message ID:
On Wed, Jan 24, 2001 at 02:24:08PM -0500, Mark-Jason Dominus wrote:
> You don't get a time optimization because goto & has large overhead.  

goto LABEL doesn't have such an overhead, so 

    sub gcd_r {
      toast: return $_[0] if $_[1] == 0;
      @_ = ($_[1], $_[0]%$_[1]);
      goto toast;

provides a time optimization. Using a block and redo is slightly
faster and avoids using the dirty word.

Hildebrant's Principle:
	If you don't know where you are going, any road will get you there.

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