--- Video Title: Functional Programming Description: Functional Programming Watch more Videos at https://www.tutorialspoint.com/videotutorials/index.htm Lecture By: Mr. Arnab Chakraborty, Tutorials Point India Private Limited --- In this session, we are discussing functional programming. We know that in case of mathematics also, if there is a particular function, if you pass any same argument to that function for multiple number of times, then the function will return you the same value. But in case of the procedural programming, if you also pass the same value for multiple number of times, then the procedure may return dependent values on its execution. So, let us go for further detailing on it. So, functional programming is style of programming language, which uses the concept of mathematical functions. A function in mathematics should always produce the same result on receiving the same argument. So, argument means here we are considering as the input argument. And in procedural languages, the flow of the program runs through the procedure and that is the control of the program is transferred to the called procedure. So, whenever a procedure will be called from a certain code, then the control will be transferred to the respective procedure body. And there, the procedure will get executed. After completion of the procedure execution, the control will come back to that very line, which is just after the line of the calling procedure statement. While control flow is transferred from one procedure to another, However, the program changes its state. In procedural programming, it is possible for procedure to produce different results, when it is called with the same argument, as the problem itself can be in different state while calling it. So, that is why it is not mandatory that in case of a procedure, whenever you are passing, same arguments for multiple number of times, the procedure will return you the same value, because depending upon the state of your program, the procedure may return different values as outcome. So, this is property, this is a property as well as a drawback of procedural programming, in which the sequence of or timing of the procedure execution becomes very important, and the output, the outcome of the procedure depends upon the state of the program. Functional programming provides means of computational as mathematical functions, which produces results irrespective of program state. We discussed this one earlier, for the same inputs, if we pass for the multiple number of times, the functional, in case of functional programming, we will be going to get the same output, irrespective of the current state of the program, irrespective of the timing. This makes it possible to predict the behavior of the program. Next one is the functional programming uses the following concepts. So, what are the concepts they are using? Let us go through them one by one. So, first class and high order functions. So, these functions have capability to accept another function as argument or they return other functions as a result. So, this is very interesting. A function will take another function name as input argument and as a result also one function can return another function can return another function as output. So, let us discuss this pure function at first. So, these functions do not include destructive updates. That is, they do not affect any IO or memory and if they are not in use, they can easily be removed without hampering the rest of the program. So, here there is there will be no destructive updates. So, it is not actually affecting any memory location or any IO. So, when this pure functions, and when this pure functions are not getting called are not getting accessed or not getting executed you can easily remove them without disturbing the system. So, next one is our recursion. A recursion IN is a programming technique where a function calls itself repeats the program code in it unless some predefined condition matches. We know that in case of recursive algorithm there will be some base case. So, for certain inputs outputs will be known to us and where this recursive algorithm is known. So, recursion will terminate and recursive algorithm will have a capability to call itself either directly or indirectly. Direct calling means that recursive call will be within the function body itself. Indirect calling means it will be calling another function, that function in turn will be calling the parent one. So, recursion is the way of creating loops in functional programming. Next one is the strict evaluation. It is a method This is the thought of evaluating the expression passed to a function as a argument. Functional programming has two types of evaluation methods. One is the strict, that is the eager, another one is the non-strict, that is known also as the lazy. Strict evaluation always evaluates the expression before invoking the function. So, in case of strict, as it is the eager evaluation, so it will always evaluates the expression before invoking the function. In case of non-strict, Non-strict evaluation, it does not evaluate the function or the respective expression unless it is needed. So, when all the input arguments are available to evaluate one function, in case of strict, it will calculate the respective output of the respective expression. And but in case of lazy or non-strict evaluation, the respective expression will not get evaluated Even if all its inputs are available. So, whenever it will be asked for, then only the evaluation will take place in case of non-strict evaluation. Next one is our lambda calculus. Most functional programming languages use this lambda calculus and as their type systems. So, lambda expressions are executed by evaluating them as they occur. In case of lambda calculus, we do not write the respective function name. Depending upon the parameters, whatever we have passed, the number of parameters, the parameter types, the respective function will be called itself. So, in this way, this is our lambda calculus. So, where we are having the anonymous function calling. So, common Lisp, Scala, Haskell and here we are having Erlang and this f hash are some examples of functional programming languages we are going to have here. So, here we have discussed what are the different ways in which the functional programming can work and what is the functional programming, how does it differ from the procedural programming. Thanks for watching this video. TutorialsPoint.com. Simply easy learning.