chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Strange hash-table behavior in compiled code


From: Alex Shinn
Subject: Re: [Chicken-users] Strange hash-table behavior in compiled code
Date: Sun, 25 Sep 2005 20:44:42 -0500
User-agent: Wanderlust/2.10.1 (Watching The Wheels) SEMI/1.14.6 (Maruoka) FLIM/1.14.6 (Marutamachi) APEL/10.6 Emacs/21.3 (i386-pc-linux-gnu) MULE/5.0 (SAKAKI)

At Sun, 25 Sep 2005 14:38:50 +0000, Mario Domenech Goulart wrote:
> 
> I'm confused about the behavior of hash tables in compiled code.
> 
> $ cat ht.scm
> (let ((ht (make-hash-table string=?)))
>   (hash-table-set! ht "a" "b")
>   (print (hash-table-ref ht "a")))

[...]

> #;1> (use ht)
> ; loading ./ht.so ...
> #f

The default hash procedure doesn't seem to handle literal strings
correctly.  If you were to use non-literals it would work:

(let ((ht (make-hash-table string=?)))
   (hash-table-set! ht (string #\a) "b")
   (print (hash-table-ref ht (string #\a))))

In the interpreter there's no special notion of a literal value, hence
the difference.

You can fix it by manually providing the hash function:

(let ((ht (make-hash-table string=? string-hash)))
   (hash-table-set! ht "a" "b")
   (print (hash-table-ref ht "a")))

Or with the attached patch to extras.scm.

--
Alex

Attachment: extras.scm.diff
Description: Binary data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]