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

From: Stephen De Gabrielle (spdegabrielle at gmail.com)
Date: Thu Jul 3 03:33:43 EDT 2008

Thats a relief - I often look to the source in /collects (via 'Search
in files') for guidance on style/usage but could only find that idiom
once.

Thanks,

Stephen

On Wed, Jul 2, 2008 at 9:01 PM, Robby Findler <robby at cs.uchicago.edu> wrote:
> 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
>>
>>
>



-- 
Cheers,

Stephen

--
Stephen De Gabrielle
s.degabrielle at cs.ucl.ac.uk
Telephone +44 (0)20 7679 0693 (x30693)
Mobile 079 851 890 45
Project: Making Sense of Information (MaSI)
Work:http://www.uclic.ucl.ac.uk/annb/MaSI.html
Home:http://www.degabrielle.name/stephen


UCL Interaction Centre
MPEB 8th floor
University College London
Gower Street
London WC1E 6BT


Posted on the users mailing list.