I'm new to Scheme and to functional programming in general.
As part of an exercise, I try to implement a function that that takes a number n
and prints line by line first n
Fibonacci numbers
The problem is that when the program reaches the recursive call, it doesn't recognize n
and so I get contract violation error.
From exploring the web I think I need to use let
function in some way but I'm not sure how.
Here's the code:
(define fibo (lambda (n)
(if (= n 1)
1
(if (= n 2)
(begin
(display "1")
(newline)
1)
(begin
(display
(+ (fibo (- n 1)) (fibo (- n 2))))
)))))
And the error I get is:
contract violation
expected: number?
given: #<void>
argument position: 1st
other arguments...:
Thank you