On Apr 3, 2009, at 11:31 AM, leppie wrote:
I will ask on the R6RS mailing about the rationale for this.

Since as usual, we're not going to achieve anything positive
on r6rs-discuss, here is my suggestion to Eduardo and anybody
else who wants to use the hash functions.

The typical use of string-hash is to obtain an integer value
from which an index into a vector is computed.  There are two
cases for the vector length N:

1. N is a power of 2.  In this case, you compute the index
   into the vector using
     (bitwise-logand (string-hash ---) (- N 1))
   This returns a valid index between 0 and (- N 1) inclusive.

2. N is not known to be a power of 2.  In this case, you
   compute the index using
     (mod (string-hash ---) N)
   This case too returns a valid index between 0 and (- N 1)
   inclusive.

In either case, it does not matter if the value returned by
string-hash is positive, negative, or 0; you get the correct
answer anyways.  So, there is no need or utility for limiting
the value returned by string-hash to nonnegative integers.

Aziz,,,

Reply via email to