[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

11.1.3 Iterating on a dbm database

To walk over the entire database, following methos are provided.

Method: dbm-fold (dbm <dbm>) procedure knil
The basic iterator. For each key/value pair, procedure is called as (procedure key value r), where r is knil for the fist call of procedure, and the return value of the previous call for subsequent calls. Returns the result of the last call of procedure. If no data is in the database, knil is returned.

The following method returns the sum of all the integer values.
 
(dbm-fold dbm (lambda (k v r) (if (integer? v) (+ v r) r) 0))

Method: dbm-for-each (dbm <dbm>) procedure
For each key/value pair in the database dbm, procedure is called. Two arguments are passed to procedure---a key and a value. The result of procedure is discarded.

Method: dbm-map (dbm <dbm>) procedure
For each key/value pair in the database dbm, procedure is called. Two arguments are passed to procedure---a key and a value. The result of procedure is accumulated to a list which is returned as a result of dbm-map.



This document was generated by Ken Dickey on November, 28 2002 using texi2html