G'day folk,

I'm slowing working through some basic exercises to get a feel for Perl 6. I'm currently trying to create a fibonacci sequence stopping at a maximum value, or a set number of terms...


I've written this:

   use v6;

   sub MAIN($terms = 35, $maximum = 4_000_000) {
        my @sequence = gather for fibonacci($maximum) -> $number {
            state $count = 0;
            take $number if $number < $maximum && $count++ < $terms;
        };

        say @sequence;
   }

   sub fibonacci($maximum) {
       my @numbers := 0, 1, *+* ... * < $maximum;
       return @numbers;
   }

with the sequence generator kindly inspired by http://justrakudoit.wordpress.com/2010/12/29/perl-6-fibonacci-versus-haskell/ but I can't get this to compile. The syntax highlighter is telling me something's wrong because say @sequence is all blue, instead of say appearing as a keyword, and the compiler says

===SORRY!===
Confused at line 19, near "}\n\nsub fib"

It's obvious I've done something wrong, but I just can't work out what it is. Can someone show me that which will be more obvious to me when I know more Perl 6?

Thanks,

    Jacinta

Reply via email to