Category Archives: programming

Language oriented programming

The best way to write programs is to write a programming language and then start programming in that language.

If anybody thinks it is too much of effort and this statement is just an exaggeration, then I would like to disprove these thoughts in this post. My experience says that this sentence forms a basic philosophy needed to write good programs.

As usual wordpress is not good place to write about code! So refer to my original post here.

Fibonacci in O(log N)

I found this beautiful algorithm while going through suggested exercise in SICP . For more detailed discussion see

    fibiter a b p q count
| count == 0        = b
| odd count         = fibiter (b*q + a*q + a*p) (b*p + a*q) p q (count -1)
| otherwise         = fibiter a b p1 q1 (count `div` 2)
p1 = p*p + q*q
q1 = q*q + 2*p*qefficientfib = fibiter 1 0 0 1

efficientfib = fibiter 1 0 0 1

ICFP with haskell/python …ocaml??

I left my office on Friday leaving an important meeting for participating in ICFP. Anand and me started working for ICFP 2007 with great zeal. We had decided scheme as our language of choice earlier. But looking at problem it looked like haskell should be better choice. So we started for working on the problem in haskell. By the time I wrote code for first part of problem, Anand got realization that haskell should not be used as none of us had expertise as much to compete in ICFP using haskell. Guess what .. Anand started looking at various languages on language shoot-outs and even tried to learn ocaml. by next day morning my haskell code was ready but was not enough to supprt Endo using a energy starving machine Arrow! I just could not convert my code in iterative way! I assume that recursion was the problem, because I was frequently ending up with stack overflow. Meanwhile when I was busy debugging my first ever biggest code written in haskell, Anand started formalizing data structures and tricks that he would use, if he had to code it in python. By Saturday afternoon my programme to decode RNA from DNA of endo was ready. I thought cool! We can do something before lightening division of competition. But then first time I realized that even linear recursion is dangerous stuff! My programme was running happily with great speed for smaller DNAs but it could not work on whole DNA of endo!!! Anand was ready with his later half written in python which decodes RNA into an image. But I had no full RNA to give him. Anand soon concluded that in futurelabs, at-least for today there is no other language of choice than python for discriminated hackers. Hummnn so next venture was writing first part of problem also in python. Anand being big fan of python, wrote it in no time. Saturday evening to Sunday afternoon went in optimizing bits and pieces of python code. After optimizing to almost that level that now no more it can be optimized, conclusion was that python can not be language if discriminated hackers 😦 Then the team turned eyes towards ocaml. Both of us finished first chapter of ocaml book happily. Then again with thought that although it looks simple, we might encounter bigger problems as we start solving the problem, we gave up on that. Oooh at last we even tried to make C as our final weapon, but realizing that it would take lot of effort to do that in C, later gave up for ICFP – 2007 with a vision for next year 😉 By the time we encounter ICFP 2008, we hope to learn around half a dozen good languages so that we have enough tools before starting the work!


sierpinskie triangle

To see more fractals generated by me see

poem by python

what about a programming language that writes poems? 


I had horrible time in editing on this blog interface! finaly moved the post to