[plt-scheme] hash-ref 'manipulating' mutable hash-tables?

From: Stephen De Gabrielle (spdegabrielle at gmail.com)
Date: Wed Jul 2 10:08:41 EDT 2008

Thankyou (all)

I was worried about using the following;

(define (hash-cons-v ht k v)
   (hash-set! ht k (cons v (hash-ref ht k null))))

I use this all the time - so much so that I'm surprised I don't see it
more - the only place I've found it is in compiler.ss  ;    (hash-set!
ht k (cons r (hash-ref ht k (lambda () null))))


Cheers,

Stephen


On Wed, Jul 2, 2008 at 12:57 PM, Matthew Flatt <mflatt at cs.utah.edu> wrote:
> At Wed, 2 Jul 2008 10:10:11 +0100, "Stephen De Gabrielle" wrote:
>> "Caveats concerning concurrent modification: A mutable hash table can
>> be manipulated with hash-ref,"
>> --  http://docs.plt-scheme.org/reference/hashtables.html
>>
>> Is this right? How does hash-ref change a hash table?  (do mutable
>> ht's do some sort of 'query optimisation' that I'm not aware of? if
>> so; does this make them faster but less safe than immutable ht's?)
>
> No, `hash-ref' doesn't mutate the table, at least not in the current
> implementation. With respect to `hash-ref', that paragraph is meant
> just to point out that reading via `hash-ref' uses a lock, so that it's
> thread-safe (though not kill-safe) when other threads might mutate the
> table.
>
> Matthew
>


Posted on the users mailing list.