We have already explored the introduction to FP in my previous blog.

Once you get into FP, you’ll quickly start hearing the terms * lambda* and

*.*

**lambda calculus****Lambda:**

** Lambda** is basically just a symbol represented as

*that*

**λ****chose when he first defined the concept of a function. In modern**

*Alonzo Church***,**

*functional programming**means “*

**lambda***“.*

**anonymous function****Calculus:**

* Calculus* is means

*in mathematical logic for expressing computation. It is basically the mathematical study of continuous change.*

**a formal system**## Lambda Calculus:

“Lambda calculus provides a theoretical framework for describing functions and their evaluation”. It forms the basis of almost all functional programming languages today.

Now, after getting familiarity with these terminologies, let’s see some examples of lambda with respect to its properties.

## Characteristics of Lambda:

**Can be assigned to a variable**.**Anonymous functions.**

Lambda is nothing but an anonymous function. In the above two examples, valueand**even**can be used as a function, i.e.,**odd**will return**even(4)**and**true**will return**odd(4)****false.****Can be passed to functions.**Now, we can call this method by passing a lambda expression, for example,

Observe these statements closely, we can easily see the benefits of doing it. Yes, we can call

by multiple**sum()**having different**lambda expression**.**implementations****Can be returned by functions.**You can define a function that returns an anonymous function, assign that to a new function, and then call that new function. Let’s see an example:

Now again see these statements closely, we see first, the method

returns an**say()**. We are assigning it to a value**anonymous function**. Now we can easily greet anyone by just passing their name.**greet****More readable, concise and maintainable code.**

The code is very much readable and concise, as you can see in the above two examples. This helps in better maintenance of code.

## Why Lambda?

There are quite a few reasons to explain the need for lambda :

**Will I use the function anywhere else:**There are many scenarios where we just use

at the**defined function**This may seem okay at first, but as the application grows, these methods also grow at a very high rate. So the use of lambda expression can**single place.**the so-called**reduce**in these cases.**boilerplate code****Less Byte Code generated:**

Lambda generates less byte-code as compared to the functions. And considering the number of functions which are replaced by these lambdas in a big application, a much compact size of byte-code is being transferred over the network (which helps in achieving good network speed) and being persisted into the storage (which saves storage space).**Fast and Efficient:**They are fast as they follow the in-place replacement algorithm.

**Convenience:**

For a simple function that is used only in one place, a lambda is quicker and easier, and more expressive, than the alternative of declaring a whole first.

## Limitations/Shortcomings of Lambda?

Great pros often come with some limitations :

- More concise code often leads to more complex code debugging and longer synthetic call stacks.
- Developers with OOPs background often find lambda expression confusing to start with, but once comfortable, lambdas are fun.

So Lambda expressions are nothing but * anonymous functions *and are considered to be the backbone of Functional Programming paradigm.

**References: **Functional Programming Simplified by Alvin Alexander

In scala, I can’t get your example of sum(3,num * num) to work. If I separately define a function, e.g var inc = (x:Int) => x+1 and do sum(3,inc), it works.

Yes it do work, but in this you are bound for one specific implementation, but by passing it as a parameter you can pass the implementation at run time