# Problem with recursion? (was [plt-scheme] Re: Novice needs helpwriting function )

 From: Marco Morazan (morazanm at gmail.com) Date: Fri Jan 4 11:56:50 EST 2008 Previous message: Problem with recursion? (was [plt-scheme] Re: Novice needs helpwriting function ) Next message: Problem with recursion? (was [plt-scheme] Re: Novice needs helpwriting function ) Messages sorted by: [date] [thread] [subject] [author]

```> The procedure
>
>  (define (fib n)
>     (cond [(or (= n 1) (= n 2)) 1]
>          [else (+ (fib (- n 1))  (fib (- n 2)))]))
>
> is a  horrible example of recursion considering the number of recursive
> calls needed and the number of duplicated computations. That's why I could
> not withstand posting my example. :)

Well, "horrible" means different things in different contexts. My
posting was addressing the claim that the recursive definition is
"contrived." No claim was made that this is the best or most efficient
way of computing fib numbers. Issues of efficiency need to be studied,
but not while getting your first exposure to recursion.

The naive definition above is elegant, not contrived, and something
inexperienced students can understand. I would certainly not use
streams and fib numbers to teach recursion to those who are seeing it
for the first time.

Marco

```

 Posted on the users mailing list. Previous message: Problem with recursion? (was [plt-scheme] Re: Novice needs helpwriting function ) Next message: Problem with recursion? (was [plt-scheme] Re: Novice needs helpwriting function ) Messages sorted by: [date] [thread] [subject] [author]