This preview shows pages 1–8. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: CSC 324: Principles of Programming Languages Functional Programming c circlecopyrt Suzanne Stevenson 2001,2002 with revisions by Cathy Jansen 1 Part III: Functional Programming Pure Functional Languages Fundamental concept: application of (mathematical) functions to values 1. Referential transparency: The value of a function application is independent of the context in which it occurs value of f(a,b,c) depends only on the values of f , a , b and c It does not depend on the global state of computation all vars in function must be parameters 2 Pure Functional Languages 2. The concept of assignment is not part of functional programming no explicit assignment statements variables bound to values only through the association of actual parameters to formal parameters in function calls function calls have no side effects thus no need to consider global state 3. Control flow is governed by function calls and conditional expressions no iteration recursion is widely used 3 Pure Functional Languages 4. All storage management is implicit needs garbage collection 5. Functions are First Class Values Can be returned as the value of an expression Can be passed as an argument Can be put in a data structure as a value Unnamed functions exist as values 4 A program includes: 1. A set of function definitions 2. An expression to be evaluated E.g. in Scheme: 1 ]=> (define (absval x) (if (>= x 0) x ( x))) ;Value: absval 1 ]=> (absval ( 3 5)) ;Value: 2 5 LISP Functional language developed by John McCarthy in the mid 50s Semantics based on Lambda Calculus All functions operate on lists or atomic symbols: (called Sexpressions) Only five basic functions: list functions cons, car, cdr, equal, atom and one conditional construct: cond Useful for listprocessing applications Programs and data have the same syntactic form: Sexpressions Used in Artificial Intelligence 6 COMMON LISP Implementations of LISP did not completely adhere to semantics Semantics redefined to match implementations COMMON LISP has become the standard Committeedesigned language (1980s) to unify LISP variants Many defined functions Simple syntax, large language 7 SCHEME...
View
Full
Document
This note was uploaded on 02/05/2011 for the course CS 24 taught by Professor Cathy during the Summer '10 term at University of Toronto Toronto.
 Summer '10
 Cathy
 Functional Programming

Click to edit the document details