Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Bugs in gen_fib examples (pp80-81) #166

ghewson opened this Issue · 1 comment

2 participants


In both versions of gen_fib, the closure unnecessarily re-calculates the last value of @fibs. For instance, if @fibs contains (0, 1, 1), then when called for fib(3) the closure calculates fib(2) then fib(3), then when called for fib(4) it calculates fib(3) then fib(4), etc. So in both versions this line:

            for my $calc ((@fibs - 1) .. $item)

should be this:

            for my $calc (@fibs .. $item)

Also, it's not necessary to initialise the cache with fib(2). Though doing so doesn't hurt the code, it's potentially confusing. So this:

    my @fibs = (0, 1, 1);

should be this:

    my @fibs = (0, 1);

Good catch. Fixed in 0ed4d23. Thank you!

@chromatic chromatic closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.