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> (define hash-table->alist (lambda (tab) (hash-fold acons ()
Greg> tab)))

>>>>> "Michael" == Michael Livshin <cmm@verisity.com> writes:

Michael> (define ht (make-hash-table 7))

Michael> (hashq-set! ht 'a 1) (hashq-set! ht 'b 2)

Michael> (hash-fold (lambda (key value acc) (display (list key value))
Michael> (newline) (+ 1 acc)) 0 ht) ===> (a 1) (b 2) 2

Thank you very much for the help. 
So, if I want to add one to each value of hash table `ht', I can
write smth. like:

(hash-fold 
	(lambda (key value alist) 
		(hashq-set! ht key (1+ value))) 
	() ht)

It is sufficient for my purposes, but, nevertheless, 
is not there more effective way? I'd like to write smth. like

	(set! value (1+ value))

in the body of lambda (I understand, that, of course, it can not work
right now (and it does not), because, evidently, I should not have a
possibility to change value of `key' in  this way).

--
Best regards,
	Valentin.

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