[plt-scheme] How to make unit functors?

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Wed May 28 14:33:12 EDT 2003

At Wed, 28 May 2003 20:21:29 +0200, =?Windows-1252?Q?Jens_Axel_S=F8gaard?= wrote:
> I get these strange results on a WinXP 204:
> 
>   > (eq-hash-code 'j)
>   26876924
>   > (eq-hash-code 'j)
>   26876924
>   > (eq-hash-code 'j)
>   26876924
>   > (eq-hash-code 'j)
>   26876924
>   > (eq-hash-code 'j)
>   27106264
>   > (eq-hash-code 'j)
>   27106264
>   > (eq-hash-code 'j)
>   27106264
> 
> The hash code suddenly changes?
> Unless it's a bug, I'm more confused than ever.

Ok, I see. My example was broken.

It should have been

  > (define j1 'j)
  > (define j2 'J)
  > (eq? j1 j2)
  #t
  > (eq-hash-code j1)
  511627
  > (eq-hash-code J2)
  511627

and so on.

The effect you see in your transcript is that the symbol table is
garbaged collected.

`eq?' implies the same hash code. If two values can't be compared
(because no one has a reference to both at the same time), the hash
codes are unrelated.

`equal-hash-code' doesn't have this problem --- intentionally, though I
see that I didn't manage to express anything about it in the
documentation.

(Who knew that documenting hash-code functions could be so tricky?)

Matthew



Posted on the users mailing list.