This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
Re: how to work with (weak) hash tables?
Greg Harvey <Greg.Harvey@thezone.net> writes:
<a whole pile of junk>
Greg, you talk too much.
You also missed a simple and obvious way to handle this: set the value
of the hash to the value returned by the procedure.
(define (hash-for-each-value! proc hash)
(let ((len (vector-length hash)))
(do ((i 0 (+ i 1)))
((= i len) ())
(for-each (lambda (x) (set-cdr! x (proc (cdr x)))) (vector-ref hash i)))))
guile> (define x (make-hash-table 10))
guile> (hashq-set! x 'b 1)
1
guile> (hashq-set! x 'a 1)
1
guile> x
#(((a . 1)) () () () ((b . 1)) () () () () ())
guile> (hashq-ref x 'a)
1
guile> (hash-for-each-value! (lambda (x) (+ x 1)) x)
()
guile> (hashq-ref x 'a)
2
guile> (hashq-ref x 'b)
2
--
Greg