scheme_part1 - CSC 324: Principles of Programming Languages...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the 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 (abs-val x) (if (>= x 0) x (- x))) ;Value: abs-val 1 ]=> (abs-val (- 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 S-expressions) Only five basic functions: list functions cons, car, cdr, equal, atom and one conditional construct: cond Useful for list-processing applications Programs and data have the same syntactic form: S-expressions 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 Committee-designed 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.

Page1 / 32

scheme_part1 - CSC 324: Principles of Programming Languages...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online