Saturday, March 6, 2010

Functional programming

Functional programming is a programming paradigm that treats computation as the
evaluation of mathematical functions. Functional programming emphasizes the definition
of functions, in contrast to procedural programming, which emphasizes the
execution of sequential commands.
The following is the factorial function written in a functional language called Lisp:
(defun factorial (n)
(if (<= n 1) 1 ( n (factorial (− n 1))))
)
Notice that it defines the factorial function rather than give the steps to calculate it.
The factorial of n is defined as 1 if n <= 1 else it is n factorial(n − 1)

No comments:

Post a Comment