Lecture overview -- Keyboard shortcut: 'u'  Previous page: Mapping -- Keyboard shortcut: 'p'  Next page: Examples of mapping -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home    Lecture 4 - Page 9 : 34
Functional Programming in Scheme
Higher-order Functions
The mapping function

It is now time to study the implementation of the mapping function. We program a function called mymap in order not to redefine Scheme's own mapping function (a standard function in all Scheme implementations).

A possible implementation of map, called mymap:

(define (mymap f lst)
  (if (null? lst)
      '()
      (cons (f (car lst))
            (mymap f (cdr lst)))))

An implementation of map. This is not a good implementation because the recursive call is not a tail call. We leave it as an exercise to make a memory efficient implementation with tail recursion - see the exercise below.

Go to exerciseIterative mapping function
Go to exerciseTable exercise: transposing, row elimination, and column elimination.