Sunday, May 27, 2007

The beauty of Functional Programming Languages

I was always and will always be an admirer of the C programming language. It is the language of hackers and it is a language from which I got so many of my 'aha' moments. You tend to keep getting surprised by C all the time and the journey never ends.

However, today I was thinking of a problem, a simple one --> to find all permutations of a given list of numbers. I tried to solve it in C and realized how ugly it would get. Then I sat and coded the problem in Python and it reminded me of the good old days of CS 152 programming, a freshman course in my college. I present the code here .... just look and marvel at the elegance of Functional Programming (FP) . Python is not a strict FP language but it has inherited a lot from Lisp, so it has a good number of FP abstractions built in.

Here is the code




The best part is that the code follows the inductive definition of the permutation itself !!
The beauty of Functional Programming LanguagesSocialTwist Tell-a-Friend