Name: Anonymous 2007-11-30 14:12
;; Walks along `list' and for each item calls `proc' with the current item and a value
;; from the hash-table, the key of which is based on calling `identifier` with the
;; current item. The initial value for each hash-table entry is based on calling
;; `initial' on the first item satisfying `identifier'. The return value of `proc'
;; is used to set the hash-table entry.
(define (fold/hash-table list identifier proc initial)
(let ((table (make-hash-table 'equal)))
(for-each
(lambda (item)
(let* ((key (identifier item))
(new-value (proc item (hash-table-get table key (initial item)))))
(hash-table-put! table key new-value)))
list)
table))
;; from the hash-table, the key of which is based on calling `identifier` with the
;; current item. The initial value for each hash-table entry is based on calling
;; `initial' on the first item satisfying `identifier'. The return value of `proc'
;; is used to set the hash-table entry.
(define (fold/hash-table list identifier proc initial)
(let ((table (make-hash-table 'equal)))
(for-each
(lambda (item)
(let* ((key (identifier item))
(new-value (proc item (hash-table-get table key (initial item)))))
(hash-table-put! table key new-value)))
list)
table))