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

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

View Full Document Right Arrow Icon
CSC326 Functional Programming i CSC326 Functional Programming
Background image of page 1

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

View Full DocumentRight Arrow Icon
CSC326 Functional Programming ii REVISION HISTORY NUMBER DATE DESCRIPTION NAME 1.0 2011-09 JZ
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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 ) filter( 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
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 8

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 Right Arrow Icon
Ask a homework question - tutors are online