Friday, January 04, 2008

Scheme is frenk'in cool!

I get used of C and java to write bore stuff for work in past 3 months.I fed up with windows-related development that destroy ur creativity day by day.OK,Im complain too much today.

I have to tell you guys that tail recurrsive is really cool stuff that can provide a low cost for performance(in facto,when u write a fibonacci).Scheme is cool lang that include many modern programming language's feature when her was born(espeically,the GC).I just have spent a little bit of time for study the syntax and go through with 2 trivial stuffs like this.......

(define cool (lambda (x)
(if (= x 0)
0
(let sum( (num x) (sp 1)) ;sp=stationary point
(if (= num 1) sp
(sum (- num 1) (* num sp)))))))

(define cool2 (lambda (n)
(if (= n 0)
0
(let fib ( (num n) (result 1) (tmp 0))
(if (= num 1)
result
(fib (- num 1) (+ result tmp) result))))))

btw:come on,roll to say "goodbye" to Microsoft(it is evil)'s bore stuff except u're a system programmer who work with windows kernel(WRK).

2 comments:

Jabka Atu said...

I will disagree with you about recuressian -
It is true that it is easy to find it's mathematical issue of it (as the big O ) but when speaking (thinking) in scheme you can see that a simple fibonachi will be run much more then you think:

as you allready know scheme evaluate all so :
(f parametr1 parameter 2) will be evaluated as
go find f
go find paramter1
go find paramter2
set f on both paramters.

so in recuresian
an will be run one time
an-1 will be run twise
an-2 will be run 4 times
.
.
.
a1 will be run 2^{n-1} times

this is real waste

Shawn the Rock said...

aha,algorithm....before I finish to read the book of The Scheme programming lang that I cant understand why scheme's math func are
so powerful.

but sound you are right.It's a really
2~(n-1) times...saddly,I still working with windows.