# What is Functional Programming?

The main concepts of this paradigm are:

• Pure functions: The concrete input will produce always the same output.
• Recursion: There are no loops. In order to get this approach, the functions can call themselves using recursivity.
• Functions are First-Class: A function is treated as a variable, which means you can pass functions as function arguments.
• Variables are immutables: A variable cannot change its value once it is declared, but it’s possible to create new ones.

# Imperative vs Declarative

The factorial is the product of all positive integers less than or equal to a given positive number.

`n! = n * (n - 1) * (n - 2) * ... * 1`

Following this formula, we can assert that the factorial of 5 is:

`5! = 5 * 4 * 3 * 2 * 1`

But, if you noticed, the factorial of 5 is actually 5 times the factorial of 4.

`5! = 5 * 4!`

And the factorial of 4 is 4 times the factorial of 3… and so on.
It’s a recursive problem!

## Imperative programming

`function factorial(int \$number): int{    \$factorial = 1;    while (\$number >= 1) {        \$factorial *= \$number;        \$number--;    }    return \$factorial;}`

We are overriding the `\$factorial` variable in every single iteration.
We focus on “HOW”.

## Declarative programming

`(defn factorial  [number]  (if (<= number 1)    1    (* number (factorial (- number 1)))))`

As you probably may guess, FP uses a declarative paradigm.
We focus on “WHAT”.

# Conclusion

If you want to learn/practice with some FP, I definitely recommend you Phel.