Lecture overview -- Keyboard shortcut: 'u'  Previous page: Selection Control -- Keyboard shortcut: 'p'  Next page: Assignments in Functional Programs -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Help page about these notes  Alphabetic index  Course home  Lecture 3 - Page 17 : 43
Programming Paradigms
Simulation of other Paradigms and Continuations
Iterative Control

Iterative control is handled by recursion in functional programming languages

  • Iterative functions

    • Programmed with recursion in tail calls - tail recursion

    • Memory efficient

    • Every loop requires a named, recursive function

Imperative

Functional - Scheme

int gcd(int small, int large){
  int rem; 
  while (small > 0){
    rem = large % small;
    large = small;
    small = rem;
  }
  return large;
}
(define (gcd small large)
  (if (> small 0)
      (gcd 
        (remainder large small)
        small)
      large))

Euclid's gcd function programming in C with a while loop, and in Scheme with a tail recursive function