Man or boy test
Will Coleda
will at coleda.com
Thu Nov 6 14:05:06 UTC 2008
On Thu, Nov 6, 2008 at 7:33 AM, François Perrad
<francois.perrad at gadz.org> wrote:
>
> Do you know the Knuth's "man or boy" test ?
>
> If not, see http://en.wikipedia.org/wiki/Man_or_boy_test
> that contains explanations and implementations in various languages.
>
> A Perl5 implementation is :
> sub A {
> my ($k, $x1, $x2, $x3, $x4, $x5) = @_;
> my $B;
> $B = sub {
> return A(--$k, $B, $x1, $x2, $x3, $x4);
> };
> return &$x4() + &$x5() if ($k <= 0);
> return &$B();
> }
>
> print A(10, sub{1}, sub{-1}, sub{-1}, sub{1}, sub{0}), "\n";
> # the expected result is -67
>
> In r32377, I commit a Lua implementation that works on Parrot.
>
> Can we do a Perl6 implementation with the current Rakudo ?
>
> François.
I'm happy to say that that the tcl version listed at the wikipedia
page does work in partcl, albeit slowly
To see the output, you can paste it into an interactive ./tclsh
session; or you can wrap the last line in a call to puts, puts[....].
--
Will "Coke" Coleda
More information about the parrot-dev
mailing list