Lecture overview -- Keyboard shortcut: 'u'  Previous page: An example with <span>let*</span> -- Keyboard shortcut: 'p'  Next page: An implementation of letrec -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Help page about these notes  Alphabetic index  Course home  Lecture 1 - Page 41 : 49
Programming Paradigms
Introduction to Functional Programming in Scheme
The letrec namebinding construct

The letrec name binding construct allows for definition of mutually recursive functions


(letrec ((n<sub>1</sub> e<sub>1</sub>) ... (n<sub>k</sub> e<sub>k</sub>)) body-expr)

(letrec ((f1 (lambda (...) ... (f2 ...)))
         (f2 (lambda (...) ... (f1 ...)))
        )
  body-expr)

An schematic example of a typical application of letrec for local definition of two mutually recursive functions.

  • Characteristics of letrec

    • Each of the name bindings have effect in the entire letrec construct, including e1 ... ek

    • letrec can be implemented by assignments to the bound names