I have started learning Scheme as functional programming is raising its head once again! Haskell, Clojure, Coffee Script in javascript.
Boy, so here i go,
Here is my fibonacci program,
(define (fibo n)
(cond ((= 0 n) 0)
((= 1 n) 1)
(else (+ (fibo (- n 1))
(fibo (- n 2))
))))
And here is a factorial program,
(define (factprog x)
(cond ((= 0 x) 1)
(else (* x (factprog (- x 1)))
))
)
Yup, that's it. So short and so sweet. Better versions of these programs are going to appear, so, watch out!
Boy, so here i go,
Here is my fibonacci program,
(define (fibo n)
(cond ((= 0 n) 0)
((= 1 n) 1)
(else (+ (fibo (- n 1))
(fibo (- n 2))
))))
And here is a factorial program,
(define (factprog x)
(cond ((= 0 x) 1)
(else (* x (factprog (- x 1)))
))
)
Yup, that's it. So short and so sweet. Better versions of these programs are going to appear, so, watch out!
No comments:
Post a Comment