Hacker News new | past | comments | ask | show | jobs | submit login

The second one is easily translated into Perl 6:

    sub fib() {
        my $fn2 = 1;
        my $fn1 = 1;
        gather loop {
            my $oldfn2;
            ($fn1, $fn2, $oldfn2) = ($fn1 + $fn2, $fn1, $fn2);
            take $oldfn2;
        }
    }

    my @g = fib;
    for ^20 -> $i {
        say $i, @g.shift;
    }
That's untested because lazy evaluation isn't yet supported in Rakudo Perl 6, but my understanding is that feature should be up and running in the next few weeks.

I don't know enough Ruby to make heads or tails of the first example, though...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: