CSC326 Lecture 10

# CSC326 Lecture 10 - CSC326 Functional Programming i CSC326...

This preview shows pages 1–5. Sign up to view the full content.

CSC326 Functional Programming i CSC326 Functional Programming

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

View Full Document
CSC326 Functional Programming ii REVISION HISTORY NUMBER DATE DESCRIPTION NAME 1.0 2011-09 JZ
CSC326 Functional Programming iii Contents 1 Agenda 1 2 Eliminating if 1 3 Eliminating Sequential Statement 2 4 Eliminating While Statement 2 5 Eliminating Side Effect 3 6 Using functional Package 3 7 High Order Function 4 8 Recap 4 9 Index 5

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

View Full Document
CSC326 Functional Programming 1 / 5 1 Agenda • Overview • Converting Imperative Program to Functional Program • Using functional package • High Order Function Overview * You have seen some elements of functional programming! * Function as first class citenzen * Recursion used as primary control structure (no loop) * Discourage or reject statements (use function application) * Focus on list processing * No side effect (no assignment, only name binding) * High order: function that operates on functions that operates on functions Functional Programming in Python • Basic elements map( func, list ) reduce( func, list ) ﬁlter( func, list ) lambda x : expr(x) 2 Eliminating if #------ "Short-circuit" conditional calls in Python -----# # Normal statement-based flow control if <cond1>: func1() elif <cond2>: func2() else : func3() # Equivalent "short circuit" expression (<cond1> and func1()) or (<cond2> and func2()) or (func3()) # Example "short circuit" expression
This is the end of the preview. Sign up to access the rest of the document.

## CSC326 Lecture 10 - CSC326 Functional Programming i CSC326...

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

View Full Document
Ask a homework question - tutors are online