next up previous contents index
Next: Set Operations Up: Higher Order Functions Previous: Searching for an element   Contents   Index

Iterating through all elements of a list: `for-each'

This abstraction traverses through a list executing a certain procdure which is passed the current element of the list as an argument.

This function is an exception to the aforementioned functional programming style, having as its objective to cause side-effects and not to return evaluated expressions.

Such side-effects may be to display data on the screen or to send them to printer. It is obvious that procedures like this, applying the imperative programming style are sometimes needed and important as well.

(define for-each
(lambda(procedure lis)
(procedure (car lis))
(for-each procedure (cdr lis) ))))))

(define l1 (cons seven
(cons eight
(cons ...
(cons ten
(for-each ndisp! l1)
--> 7

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