I am OOP guy before reading this book (SICP) whenever i see a java 8 code it was difficult for me to understand it.
Though i gone through the basic tutorials i did not get the confidence to write a code in Java 8 /functional programming.
My Senior college who is also an FP expert suggest me to read book “Structure and interpretation of computer program ” by Harold Abelson which talks about basic of computer programming and about functional programming.
here in this post i am writing notes from SICP book which helps me to understand functional programming paradigm.
The examples in books are in LISP language, i will not go deep down in examples rather i will give the concise overview of the functional programming important concepts which an OO guy can refer while writing FP code in java 8 or any other FP language.
In programming we deal with two kinds of elements :
1. Procedures (aka methods, functions )
2. Data .
The data is the stuff we want to manipulate and procedures are descriptions of the rules for manipulating the data.
The Golden Rule :
The code is the data.
the whole Functional Programming is in this simple sentence. ( i am going to write complete post on this sentence soon )
In mathematics we usually concern with declarative ( what is ) descriptions, whereas in computer science we are usually concerned with imperative( how to ) descriptions.
Q. What is Predicate..?
The word predicate is used for procedures or expressions which returns true / false as a response.
Q. What is lambda.
The lamda is the way to create procedures without providing the name for the procedure.
Eg : lamda ( )
Its same as defining the procedure but without name
procedure with name
( define (plus4 x) (+ x 4) )
procedure without name , lambda
(lambda (x) (+ x 4 ) )
we can read this as : The procedure of an argument x that adds x and 4 .
Q. Three important elements of every powerful computer language.
Consider any powerful programming language it provides the basic elements to construct the complex solutions.
Every powerful language has three mechanisms to accomplish this :
1. primitive expressions : which represents the simplest entities the language represents.
eg. +, _, *, / .
2. combinations ( Compound elements ) : which use the simplest entities to build the compound elements . means takes the primitives and make bigger complex entities by using them.
eg. agggregate functions, arrys , lists.
3.Abstractions : using which the compound elements can be named and manipulated as a unit.
Its like taking complex things containing primitives and draw boxes around them. Name the complex solutions to build more complex solutions.
Eg. Mathamatical addition of any number .
Q. What does it mean by compound data..?
The data which represents the group of data is compound data.
Eg. consider the method add( int, int ) here if we pass add(30,10) is the simple data but,
if we pass add ( (4/2) , (5/5) ) the arguments of this add methods are the compound data.
The use of compound data enables us to increase the modularity of our programs.
Q. What is data abstraction?
It’s process of hiding the underlying representation of data.
SICP definition :
Is it the general technique of isolating the parts of a program that deal with how data objects are represented from the parts of a program that deal with how data objects are used is a powerful design methodology called data abstraction .