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> Yeah, I didn't think too much on it; I just finished that big,
Greg> long winding mail and went to get a sandwich, took a bite and
Greg> said 'doh!, that's so simple' :)

Greg> (define (hash-for-each-value! proc hash) (let ((len
Greg> (vector-length hash))) (do ((i 0 (+ i 1))) ((= i len)
Greg> *unspecified*) ;Better than an empty list (for-each (lambda (x)
Greg> (let ((res (proc (car x) (cdr x)))) (if (not (unspecified? res))
Greg> (set-cdr! x res)))) (vector-ref hash i)))))
OK. As minimum, I learn guile a bit more - I did not know about the
`unspecified?' :).

Greg> Note, though, that it's now possible to mess up the keys again,
Greg> if you have a non-immediate there (this is why I restricted it
Greg> to only the value; I did think about that part ;):
Surely, but in many "realistic" situations it is not sufficient to know 
just a `value' to change it - it is important to know the `key'.

At the same time, `set!' is used much more frequently that
`set-car!' or `string-set!', so, the probability to make error is
lower in the new version.

But all this are just trivial thoughts; you gave me the solution I
needed. 

--
Best regards,
	Valentin.

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