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 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 definitely doesn't grow the stack: perl -E '$n = 0; sub wah { return if $_[0] < 1; $n++; @_=($_[0]-1); goto }; wah(shift); say "done $n"' 1000 But IIRC goto is more about fooling caller() than TCO, so its not that really fast thing some users expect. On 18 November 2016 at

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