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

From: Robby Findler (robby at cs.uchicago.edu)
Date: Wed Jul 2 16:01:36 EDT 2008

I use that all the time myself too, but mostly in scripts. (I usually
call it hash-cons!). I also use hash-inc! that defaults to 0 and adds
1 to the binding.

Robby

On Wed, Jul 2, 2008 at 9:08 AM, Stephen De Gabrielle
<spdegabrielle at gmail.com> wrote:
> 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
>>
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>


Posted on the users mailing list.