[prev] 50 [next]

Higher-order Functions (cont)

Implementation of map() (i.e. applyToList())

void map(List L, int (*f)(int))
{
   if (empty(L))
      /* nothing to do/;
   else {
      head(L) = (*f)(head(L));
      tail(L) = map(tail(L), f);
   }
}

Applies a function of type (int → int) to each list element