hash-salt Takashi Kato 04 Feb 2016 08:21 UTC
Re: hash-salt taylanbayirli@xxxxxx 04 Feb 2016 09:21 UTC

hash-salt Takashi Kato 04 Feb 2016 08:21 UTC

Hi,

I'm currently implementing SRFI-126 on Sagittarius and have got a question
about hash-salt. The description says it needs to be expanded to exact
non-negative integer but it would be the same value for each time if
implementations cache the result of compiled code. I think I know the
answer but is this expected behaviour?

And just found out that on sample implementations hash-salt are implemented
as a procedure. Should this be something like this (on R6RS)?

(define-syntax hash-salt
  (lambda (x)
    (define *hash-salt*
      (let ((seed (get-environment-variable "SRFI_126_HASH_SEED")))
        (if (or (not seed) (string=? seed ""))
            (random-integer (greatest-fixnum))
            (modulo
             (fold (lambda (char result)
                     (+ (char->integer char) result))
                   0
                   (string->list seed))
             (greatest-fixnum)))))
    (syntax-case x ()
      ((_) *hash-salt*))))

Cheers,

--
_/_/
Takashi Kato
E-mail: ktakashi19@gmail.com