next up previous contents index
Next: Selecting elements from a Up: Higher Order Functions Previous: Converting all elements in   Contents   Index


Converting the `map' function: `mapc'

This abstraction illustrates the usefulness of the abstraction `curry'. `mapc' converts the `map' function, which takes two arguments into a function expecting only one argument.

The `map' functionexpects a modifier and a list as arguments. The modifier is applied to all elements of the list. If for a certain application the modifier remains constant but the list varies from case to case, it seems to be useful to have a function that expects only the list as argument. Such a function is built by `mapc'.


\begin{lstlisting}[language=Scm]{}
(define mapc (curry map))
;
;;; Example 1:
;;...
...ree
(cons four
nil)))))
(ldisp! (succ* l1))
--> 2
3
4
5
\end{lstlisting}



domain access counter Georg P. Loczewski 2004-03-05