{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture_04

# lecture_04 - BIOS 735 Statistical Computing Michael Wu...

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

BIOS 735: Statistical Computing Michael Wu Lecture 4: Functional Programming and Intro to Programming Structures August 30, 2011 Michael Wu (Lecture 4) BIOS 735 August 30, 2011 1 / 14

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

View Full Document
Functional Programming Functional programming = programming paradigm that treats computation as evaluation of mathematical functions without side effects (Wiki) Subparadigm of Declarative Programming Key Concept: you are asking for a result without clear, in-depth description of how to get the result NOT like what we typically learn in CS Another Key Concept: no side effects . Beyond returning a value, functions do not generally modify particular parameters. Doesn’t interact as much with outside world. a = 10 f = function(x) { print(a); a = 20; print(a); return(x)} f(99) a Generally slower and less efﬁcient than imperative languages, but specialized operations can be very fast Emphasis on composition and arrangement of functions (without details) while imperative progamming focuses on the steps to carry out actions. Michael Wu (Lecture 4) BIOS 735 August 30, 2011 2 / 14
Example Imperative programming (C++) int fibonacci(int iterations) { int first = 0, second = 1; // seed values for (int i = 0; i < iterations; ++i) { int sum = first + second; first = second; second = sum; } return first; } std::cout << fibonacci(10) << "\n"; Functional programming (R) hold = function(a, b){ if (a <100) return(c(b, hold(b,a+b))) else return(a+b) } hold(0,1) key difference: Imperative puts commands in a loop. On the other hand, the Functional allows focus on the mathematical relationship (recursion) that deﬁnes ﬁbonnacci. Michael Wu (Lecture 4) BIOS 735 August 30, 2011 3 / 14

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

View Full Document
R is a very well thought out and well designed language. Why functional programming? Clearer, more compact. Possibly faster execution depending on your goal. Less Code = Less Debugging Easy transition to parallel programming Very natural for statisticians and mathematicians. Michael Wu (Lecture 4)
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 15

lecture_04 - BIOS 735 Statistical Computing Michael Wu...

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

View Full Document
Ask a homework question - tutors are online