Jenda Krynicky wrote:

> I believe they meant "goto &NAME".

<illuminating example snipped>

> This way perl doesn't create a new record in the call stack every
> time you "call" the _fib().
> As you can see if you comment out the return in fib_() and remove
> the comment from "croak ..." and "use Carp;". (die() with stack
> print).
>
> See
> perldoc -f goto

Thanks :). That's great. I don't use goto much, except for a couple of very
specific situations, so I hadn't  read the docs for goto. It seems I missed
a very interesting beast in goto &NAME. In fact , I sent a friend of mine
some code recently that would have been improved in one place by its use.

But I still have a question :). As I understand it when tail-call
optimization is done automatically there are two advantages. One is that the
stack doesn't grow out of control, so that you don't have to worry about
blowing it up if you recurse very deeply. The other is that the overhead of
successive calls is eliminated. In theory (but, I think, often not in
practice) the optimized routine should be as efficient as the equivalent
iterative routine. Using goto &name has the first advantage, but does it
have the second? That is, does goto &NAME have the same overhead as a normal
call?

Does anyone write this kind of recursive function regularly? I mean, is it
idiomatic in the more rarefied Perl circles? Or is it better (from a style
point of view) to use iterative constructs even in places where recursion is
more natural, but tail-call optimization would be required?

Thanks
Tagore Smith


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to