Saturday, 21 November 2015

Functional Programming

Functional Programming: -

  • Languages- Pascal, C, Modula 2, Ada, are imperative languages ​​Because basic construct is a command
  • Heavily Influenced by Von Neumann architecture - includes a store (memory), on instruction used to identify the next instruction to be fetched from store 
  • computation model has control structures did Determine the sequencing of instructions- use assignments to make incremental modifications to the store.
Properties (Imperative Languages): -
  • Principal operation- assignment of values ​​to variables
  • programs are command oriented-> They carry out algorithms with statement level sequence control, selection and repetition Usually by
  • Programs are organized as Blocks-> DataControl is dominated by scope rules
  • computing is done by effect (changes to the store)
Computing: -
  • Intrinsic to imperative programming plays havoc with some of the mathematical properties- essential to prove the correctness of programs.
  • Example: - Is addition commutative Inn on imperative program, Doesburg write (a + b) always produce the same value as write (b + a).  
                                                            Most likely give different results for the two versions of this program. DEPENDING on the order of evaluation of expressions
  • Anomaly is Caused by the side effects in the expression being Evaluated 
  • Programming by effect lies at the heart of imperative programming.
  • If we depend on imperative programs we must discard many of the basic properties of mathematics (associative, commutative, law of addition and multiplication and the distributive law for multiplication over addition.
Functional Programming: -
  • Provides paradigm of alternative notion of programming 
  • Avoids the problem of side effects
  • Functional languages ​​Concerned with the Data Objects and value instead of variable
Values: -
  • Bound with identifiers
  • Once made thesis bindings can not change
  • principal operation is function application
Functions: -
  • Treated as first class objects 
  • May be stored in data structures.
  • passed as parameter
  • returned as function results
  * Functional language supplies primitive functions
  * Programmer uses function constructors to define new functions 
  * Program Execution is by evaluation of expression 
  * Sequence Control depends on selection and recursion 

Pure Functional language: -
  • No assignments language 
  • Values ​​are Communicated by the use of parameters to functions.
  • thesis restrictions enforce a discipline on the programmer did Avoids Side Effects
  • Functional languages ​​- referentially transparent
Principle of Referential Transparency: -
  • value of the function is Determined by the values ​​of its arguments and the context in Which the function application Appears.
  • It is independents of the History of the execution
  • Evaluation of a function with the same argument Produces the same result every time it is invoked
  • An expression will produce the same value each time it is Evaluated in a Given Context
  • Guarantees the validity of the property substituting equals for equals.
LISP: - 
  • List Processing [1956]
  • started with on Artificial Intelligence Group at MIT under John McCarthy 
  • Implemented (1960) on an IBM 704 (McCarthy and his students).
  • Had the first Fortran implementation 
  • Early Example of interactive computing 
  • original development used expression S (S- symbolic language)
  • Lisp with 2M expression (intention of developing Algol like version)
  • When Lisp interpreter written in Lisp what with S Lisp expression Which Dropped 2 
  • Principle version based on Lisp 1.5 include Interlisp, FranzLisp, MacLisp, CommonLisp and Scheme
  • High level notation for selection
  • Fuctions are defined as expressions 
  • Repetitive tasks by recursions
  • Parameters are passed to functions by value
  • Program Consists -> set of function definitions Followed by a list of expression did may include function evaluation.
Scheme syntax: -
  • Scheme version chosen Because of small size and uniform treatment of functions
  • BasicObject in Scheme - S expression


Protected by Copyscape Web Plagiarism Check

No comments:

Post a Comment