diff --git a/ice-9/session.scm b/ice-9/session.scm index 5901eba23..208230938 100644 --- a/ice-9/session.scm +++ b/ice-9/session.scm @@ -264,12 +264,18 @@ The forest traversed is the image of the forest generated by root modules returned by INIT-THUNK and the generator TRAVERSE. It is an image under the mapping EXTRACT." (lambda (fold-module init) - (let rec ((data init) - (modules (init-thunk))) - (do ((modules modules (cdr modules)) - (data data (rec (fold-module (extract (car modules)) data) - (traverse (car modules))))) - ((null? modules) data))))) + (let* ((table (make-hash-table 31)) + (first? (lambda (obj) + (and (not (hash-ref table obj)) + (hash-create-handle! table obj #t))))) + (let rec ((data init) + (modules (init-thunk))) + (do ((modules modules (cdr modules)) + (data data (if (first? (car modules)) + (rec (fold-module (extract (car modules)) data) + (traverse (car modules))) + data))) + ((null? modules) data)))))) (define-public (apropos-fold-accessible module) (make-fold-modules (lambda () (list module))