On 04/03/2009 07:18 AM, Alex Queiroz wrote:
> Hallo,
>
> On 4/3/09, leppie<[email protected]>  wrote:
>> Hi
>>
>> The R6RS states:
>>
>> "Hash-function should accept a key as an argument and should return a
>> non-negative exact integer object."
>>
>> This only the only place that mentions a non-negative integer.
>>
>> What is the rationale for making the hash value non-negative?
>>
>
>       Maybe because the output is supposed to be used as an index into
> some hash table array.

Huh?  You can't use a hash value as an index into an array unless you
know the hash is less than the length of the array, which is rare.
You have to take the modulo of the hash value.

In which case a negative value works just fine.  So yes, it makes
sense to allow negative hash values if that allows better use of fixnum.

Java hashCode returns a (32-bit signed) int, and that is what Kawa
uses and will continue to use for hash "protocol".  Nothing else
would be sane on the JVM.
-- 
        --Per Bothner
[email protected]   http://per.bothner.com/

_______________________________________________
r6rs-discuss mailing list
[email protected]
http://lists.r6rs.org/cgi-bin/mailman/listinfo/r6rs-discuss

Reply via email to