Re: tail call optimization

2016-11-18 Thread Luca Ferrari
On Fri, Nov 18, 2016 at 4:57 AM, Andrew Kirkpatrick wrote: > But IIRC goto &func is more about fooling caller() than TCO, so its > not that really fast thing some users expect. Yes, it's more a way to not change the call stack than to optimize it. Luca

Re: tail call optimization

2016-11-17 Thread Andrew Kirkpatrick
Perl5 goto &func definitely doesn't grow the stack: perl -E '$n = 0; sub wah { return if $_[0] < 1; $n++; @_=($_[0]-1); goto &wah; }; wah(shift); say "done $n"' 1000 But IIRC goto &func is more about fooling caller() than TCO, so its not that really fast thing some users expect. On 18 Novemb

Re: tail call optimization

2016-11-17 Thread Elizabeth Mattijsen
Hiroki, > On 17 Nov 2016, at 10:49, Hiroki Horiuchi wrote: > I think the tail call is optimized in the following Perl 5 code. Are you sure? Have you benchmarked it? I seem to recall that using goto like that in Perl 5 only makes sure that any backtrace doesn’t get longer. But that it comes

tail call optimization

2016-11-17 Thread Hiroki Horiuchi
Hello. I think the tail call is optimized in the following Perl 5 code. How can I do the same in Perl 6? -- #!/usr/bin/env perl v5; use strict; use warnings; local $\ = "\n"; sub reduce_sum($$) { my ($sum, $range) = @_; return $$sum unless @$range; my $lhs = shift @$ran