[plt-scheme] Re: TypedScheme: alpha release

From: Kyle Smith (airfoil at bellsouth.net)
Date: Tue Dec 19 12:29:41 EST 2006

Chris Warrington <chrisw at ...> writes:

> 
> I'd say that is was. Try this:
> (module fib (planet "typed-scheme.ss"  ("plt" "typed-scheme.plt" 1))
>    (define: (fib [n : number]) : number
>      (let: ([base? : boolean (or (= 0 n) (= 1 n))])
>        (if base? 1
>            (+ (fib (- n 1)) (fib (- n 2)))))))
> 

Actually, your fib function is off by one step: with this modification below,

  (define: (fib [n : number]) : number
    (let: ([base? : boolean (or (= 0 n) (= 1 n))])
          (if base? (if (= 0 n) 0 1)
              (+ (fib (- n 1)) (fib (- n 2))))))

  (printf "~a ~a~n" 2 (fib 2))
  (printf "~a ~a~n" 3 (fib 3))
  (printf "~a ~a~n" 4 (fib 4))
  (printf "~a ~a~n" 5 (fib 5))
  (printf "~a ~a~n" 6 (fib 6))
  (printf "~a ~a~n" 7 (fib 7))
  (printf "~a ~a~n" 8 (fib 8))
  (printf "~a ~a~n" 9 (fib 9))
  (printf "~a ~a~n" 10 (fib 10))

=>

checked fib
2 1
3 2
4 3
5 5
6 8
7 13
8 21
9 34
10 55

You get the output that you expect from fib.

Cheers,

--kyle
airfoil at bellsouth dot net
schemekeys.blogspot.net




Posted on the users mailing list.