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

Re: Can Perl do tail recursion?

From:
Simon Cozens
Date:
January 24, 2001 11:30
Subject:
Re: Can Perl do tail recursion?
Message ID:
20010124193005.A17539@pembro26.pmb.ox.ac.uk
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.



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