This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: how to work with (weak) hash tables?


>>>>> "Greg" == Greg Harvey <Greg.Harvey@thezone.net> writes:

Greg> You also missed a simple and obvious way to handle this: set the
Greg> value of the hash to the value returned by the procedure.


Greg> (define (hash-for-each-value! proc hash) (let ((len
Greg> (vector-length hash))) (do ((i 0 (+ i 1))) ((= i len) ())
Greg> (for-each (lambda (x) (set-cdr! x (proc (cdr x)))) (vector-ref
Greg> hash i)))))
This is exactly a solution that I had in mind. With two minor changes:
	1. `proc' must be a function of two arguments `(key value)'
	2. if `proc' returns #unspecified, set-cdr! is not called
		(that is why, I thought about C version of this).

Thank you (again) for your help.

--
Best regards,
	Valentin.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]