This is the mail archive of the guile@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] |
Han-Wen Nienhuys <hanwen@cs.uu.nl> writes:
> I am still muddling along with integrating GUILE in LilyPond, and I
> have a question. I want to replace an existing C++ implementation of
> identifier tables by GUILE's code. I've managed to replace
>
> Hash_table<String,Identifier*>
>
> by
>
> Hash_table<SCM, Identifier*>
>
> and use interning and GUILE symbols for doing the identifier lookup.
> But I'd like to use GUILE's hash tables as well, and that's were my
> question comes in: is there an interface that allows me to iterate
> through the entries of a GUILE hash table?
I use the following, which should definitely be provided somewhere
in guile, but isn't, AFAIK:
(define (hash-table-for-each fn ht)
(do ((i 0 (+ 1 i)))
((= i (vector-length ht)))
(do ((alist (vector-ref ht i) (cdr alist)))
((null? alist) #t)
(fn (car (car alist)) (cdr (car alist))))))
(define (hash-table-map fn ht)
(do ((i 0 (+ 1 i))
(ret-ls '()))
((= i (vector-length ht)) (reverse ret-ls))
(do ((alist (vector-ref ht i) (cdr alist)))
((null? alist) #t)
(set! ret-ls (cons (fn (car (car alist)) (cdr (car alist))) ret-ls)))))
If you want a C version, you can run the above code through hobbit, or
tranlate it to C by hand.
-russ
--
"Whenever you find yourself on the side of the majority, it is time to
pause and reflect."
-- Mark Twain