### Documentation typo in CodePatterns

Posted:

**Fri Sep 18, 2015 2:03 pm**Hi,

I realized that the code for the fibonacci functions in the codepatterns

section is wrong: http://www.newlisp.org/CodePatterns.html#toc-5

The code is:

Should be:

The iterative version should be fixed also, something like

that should be correct:

I realized that the code for the fibonacci functions in the codepatterns

section is wrong: http://www.newlisp.org/CodePatterns.html#toc-5

The code is:

- Code: Select all
`; classic recursion`

; slow and resource hungry

(define (fib n)

(if (< n 2) 1

(+ (fib (- n 1))

(fib (- n 2)))))

> (fib 12)

233

Should be:

- Code: Select all
`; classic recursion`

; slow and resource hungry

(define (fib n)

(if (< n 2) n

(+ (fib (- n 1))

(fib (- n 2)))))

> (fib 12)

144

The iterative version should be fixed also, something like

that should be correct:

- Code: Select all
`; iteration`

; fast and also returns the whole list

(define (fibo n , f)

(set 'f '(1 0))

(case n

(0 (1 f))

(1 f)

(true

(dotimes (i (- n 1))

(push (+ (f 0) (f 1)) f)))))

> (fibo 12)

(144 89 55 34 21 13 8 5 3 2 1 1 0)